You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Codewars Council meets at a circular table with n seats. Depending
on the day d of the month, d people will be chosen as leaders of the
council. These d leaders are spaced equidistantly from each other on the
table, like spokes on a wheel. The leaders are chosen based on which
grouping of d equidistant people have the largest summed honor. The
honor of the participants for that day in the Council is given in an
array arr of length n. Return the combined honor of the d leaders of the
Council.
Given conditions: n % d == 0, ie. there will be no invalid cases. All groupings go fully
around the circle. 1 <= d <= 31, as you can't have 32 days in a month. n > 0 because you can't have a Council of 0 people. (You also can't have
a table with 0 open seats, then it's just a nightstand or something)
You can have negative honor on Codewars (but it is hard to do) and the
solution may be negative.
Example:
Hint: Something important to note is that you (usually) don't have to evaluate
every sum in the array, as after n/d repetitions the sums loop over on
themselves.
Second task
You are going to be given an array of integers. Your job is to take that
array and find an index N where the sum of the integers to the left of N
is equal to the sum of the integers to the right of N. If there is no
index that would make this happen, return -1.
For example:
Let's say you are given the array {1,2,3,4,3,2,1}:
Your function will return the index 3, because at the 3rd position of
the array, the sum of left side of the index ({1,2,3}) and the sum of
the right side of the index ({3,2,1}) both equal 6.
Let's look at another one.
You are given the array {1,100,50,-51,1,1}:
Your function will return the index 1, because at the 1st position of
the array, the sum of left side of the index ({1}) and the sum of the
right side of the index ({50,-51,1,1}) both equal 1.
Last one:
You are given the array {20,10,-80,10,10,15,35}
At index 0 the left side is {}
The right side is {10,-80,10,10,15,35}
They both are equal to 0 when added. (Empty arrays are equal to 0 in
this problem)
Index 0 is the place where the left side and right side are equal.
Note: Please remember that in most programming/scripting languages the
index of an array starts at 0.
Input:
An integer array of length 0 < arr < 1000. The numbers in the array can
be any integer positive or negative.
Output:
The lowest index N where the side to the left of N is equal to the side
to the right of N. If you do not find an index that fits these rules,
then you will return -1.
Note: If you are given an array with multiple answers, return the lowest
correct index.
Third task
Your job is to group the words in anagrams.
What is an anagram ?
star and tsar are anagram of each other because you can rearrange the
letters for star to obtain tsar.
Example
A typical test could be :
A food delivery truck carrying boxes of delicious sausages has arrived
and it's your job to unpack them and put them in the store's display
counter.
The truck is filled with boxes of goods. Among the goods, there are
various types of sausages. Straight sausages I, curvy sausages ), even
twirly sausages @ and many more. The safest way to tell any type of
sausage apart from other goods is by the packaging [], used exclusively
by sausages. Make sure to ignore other goods, those will be taken care
of by someone else. Once you have unpacked all the sausages, just lay
them out in the display counter (string) in the same order in which they
came in boxes with one space " " in-between every sausage. Oh, and watch
out for spoiled or damaged sausage packs, did I tell you about those?
The sausages are always packed in fours and each pack contains only one
sausage type, so whenever there is any irregularity, the sausages are
probably spoiled or damaged and the whole pack should be thrown out!
Now we're getting to the best part - your reward! Instead of money,
you'll be paid in something far better - sausages! Every fifth undamaged
processed pack of sausages doesn't go to the counter, instead it's yours
to keep. Don't go spending it all at once!
If the truck arrives completely empty, only with empty boxes or only
with goods that are not sausages, the display counter will simply stay
empty "". Unlike truck and boxes that may be empty, every existing
product is a non-empty string.
Example:
Input (truck with 5 boxes containing 11 products):
[ [ "(-)", "[IIII]", "[))))]" ], [ "IuI", "[llll]" ], [ "[@@@@]", "UwU",
"[IlII]" ], [ "IuI", "[))))]", "x" ], [] ]
"Truck is an array, packages are arrays, packages of goods are strings"
Output (four sets of sausages):
"I I I I ) ) ) ) l l l l @ @ @ @"
Explanation: The last box is empty and is therefore ignored
Packages with products that are not sausages are ignored - "(-)", "IuI",
"UwU", "IuI", "x"
One damaged package gets thrown out - "[IlII]"
Fifth undamaged package is used as your reward and is therefore excluded
from the output: "[))))]"
More examples of input and expected output can be seen in the example
test cases
Fifth task
Given an object of likely nested objects, where the final element is an
array containing positive integers, write a function that returns the
name of the root property that a particular integer lives in.
E.g
Heres what the object looks like:
getRootProperty(object, 9) returns "one" because "one" is the root
property name where the value 9 is buried in (in an array), other root
properties may also have 9 buried in it but you should always return the
first
Another Example
Given an array arr of strings, complete the function by calculating the
total perimeter of all the islands. Each piece of land will be marked
with 'X' while the water fields are represented as 'O'. Consider each
tile being a perfect 1 x 1 piece of land. Some examples for better
visualization:
['XOOXO',
'XOOXO',
'OOOXO',
'XXOXO',
'OXOOO']
which represents:
should return: "Total land perimeter: 24".
Following input:
['XOOO',
'XOXO',
'XOXO',
'OOXX',
'OOOO']
which represents:
should return: "Total land perimeter: 18"
The text was updated successfully, but these errors were encountered:
First task
The Codewars Council meets at a circular table with n seats. Depending
on the day d of the month, d people will be chosen as leaders of the
council. These d leaders are spaced equidistantly from each other on the
table, like spokes on a wheel. The leaders are chosen based on which
grouping of d equidistant people have the largest summed honor. The
honor of the participants for that day in the Council is given in an
array arr of length n. Return the combined honor of the d leaders of the
Council.
Given conditions:
n % d == 0
, ie. there will be no invalid cases. All groupings go fullyaround the circle.
1 <= d <= 31
, as you can't have 32 days in a month.n > 0
because you can't have a Council of 0 people. (You also can't havea table with 0 open seats, then it's just a nightstand or something)
You can have negative honor on Codewars (but it is hard to do) and the
solution may be negative.
Example:
Hint:
Something important to note is that you (usually) don't have to evaluate
every sum in the array, as after n/d repetitions the sums loop over on
themselves.
Second task
You are going to be given an array of integers. Your job is to take that
array and find an index N where the sum of the integers to the left of N
is equal to the sum of the integers to the right of N. If there is no
index that would make this happen, return
-1
.For example:
Let's say you are given the array
{1,2,3,4,3,2,1}
:Your function will return the index 3, because at the 3rd position of
the array, the sum of left side of the index (
{1,2,3}
) and the sum ofthe right side of the index (
{3,2,1}
) both equal 6.Let's look at another one.
You are given the array
{1,100,50,-51,1,1}
:Your function will return the index 1, because at the 1st position of
the array, the sum of left side of the index (
{1}
) and the sum of theright side of the index (
{50,-51,1,1}
) both equal 1.Last one:
You are given the array
{20,10,-80,10,10,15,35}
At index 0 the left side is {}
The right side is
{10,-80,10,10,15,35}
They both are equal to 0 when added. (Empty arrays are equal to 0 in
this problem)
Index 0 is the place where the left side and right side are equal.
Note: Please remember that in most programming/scripting languages the
index of an array starts at 0.
Input:
An integer array of length
0 < arr < 1000
. The numbers in the array canbe any integer positive or negative.
Output:
The lowest index N where the side to the left of N is equal to the side
to the right of N. If you do not find an index that fits these rules,
then you will return
-1
.Note:
If you are given an array with multiple answers, return the lowest
correct index.
Third task
Your job is to group the words in anagrams.
What is an anagram ?
star and tsar are anagram of each other because you can rearrange the
letters for star to obtain tsar.
Example
A typical test could be :
Fourth task
Unpack delicious sausages!
A food delivery truck carrying boxes of delicious sausages has arrived
and it's your job to unpack them and put them in the store's display
counter.
The truck is filled with boxes of goods. Among the goods, there are
various types of sausages. Straight sausages
I
, curvy sausages)
, eventwirly sausages
@
and many more. The safest way to tell any type ofsausage apart from other goods is by the packaging
[]
, used exclusivelyby sausages. Make sure to ignore other goods, those will be taken care
of by someone else. Once you have unpacked all the sausages, just lay
them out in the display counter (string) in the same order in which they
came in boxes with one space " " in-between every sausage. Oh, and watch
out for spoiled or damaged sausage packs, did I tell you about those?
The sausages are always packed in fours and each pack contains only one
sausage type, so whenever there is any irregularity, the sausages are
probably spoiled or damaged and the whole pack should be thrown out!
Now we're getting to the best part - your reward! Instead of money,
you'll be paid in something far better - sausages! Every fifth undamaged
processed pack of sausages doesn't go to the counter, instead it's yours
to keep. Don't go spending it all at once!
If the truck arrives completely empty, only with empty boxes or only
with goods that are not sausages, the display counter will simply stay
empty "". Unlike truck and boxes that may be empty, every existing
product is a non-empty string.
Example:
Explanation:
The last box is empty and is therefore ignored
Packages with products that are not sausages are ignored - "(-)", "IuI",
"UwU", "IuI", "x"
One damaged package gets thrown out - "[IlII]"
Fifth undamaged package is used as your reward and is therefore excluded
from the output: "[))))]"
More examples of input and expected output can be seen in the example
test cases
Fifth task
Given an object of likely nested objects, where the final element is an
array containing positive integers, write a function that returns the
name of the root property that a particular integer lives in.
E.g
Heres what the object looks like:
getRootProperty(object, 9)
returns "one" because "one" is the rootproperty name where the value 9 is buried in (in an array), other root
properties may also have 9 buried in it but you should always return the
first
Another Example
return null if the value isn't found.
Sixth task
Given an array arr of strings, complete the function by calculating the
total perimeter of all the islands. Each piece of land will be marked
with 'X' while the water fields are represented as 'O'. Consider each
tile being a perfect 1 x 1 piece of land. Some examples for better
visualization:
which represents:
should return: "Total land perimeter: 24".
Following input:
which represents:
should return: "Total land perimeter: 18"
The text was updated successfully, but these errors were encountered: