#76 Ones and Zeros


Given an array of one's and zero's convert the equivalent binary value to an integer.


Eg: [0, 0, 0, 1] is treated as 0001 which is the binary representation of 1.


Examples:


Testing: [0, 0, 0, 1] ==> 1

Testing: [0, 0, 1, 0] ==> 2

Testing: [0, 1, 0, 1] ==> 5

Testing: [1, 0, 0, 1] ==> 9

Testing: [0, 0, 1, 0] ==> 2

Testing: [0, 1, 1, 0] ==> 6

Testing: [1, 1, 1, 1] ==> 15

Testing: [1, 0, 1, 1] ==> 11

However, the arrays can have varying lengths, not just limited to 4.




 #75 Numericals of a String


You are given an input string.


For each symbol in the string if it's the first character occurence, replace it with a '1', else replace it with the amount of times you've already seen it...


But will your code be performant enough?


Examples:

input   =  "Hello, World!"

result  =  "1112111121311"


input   =  "aaaaaaaaaaaa"

result  =  "123456789101112"

Note: there will be no int domain overflow (character occurences will be less than 2 billion).




 #74 CamelCase to underscore


You wrote all your unit test names in camelCase. But some of your colleagues have troubles reading these long test names. So you make a compromise to switch to underscore separation.


To make these changes fast you wrote a class to translate a camelCase name into an underscore separated name.


Implement the ToUnderscore() method.


Example:


"ThisIsAUnitTest" => "This_Is_A_Unit_Test"


But of course there are always special cases...


You also have some calculation tests. Make sure the results don't get splitted by underscores. So only add an underscore in front of the first number.


Also Some people already used underscore names in their tests. You don't want to change them. But if they are not splitted correct you should adjust them.


Some of your colleagues mark their tests with a leading and trailing underscore. Don't remove this.


And of course you should handle empty strings to avoid unnecessary errors. Just return an empty string then.


Example:


"Calculate15Plus5Equals20" => "Calculate_15_Plus_5_Equals_20"


"This_Is_Already_Splitted_Correct" => "This_Is_Already_Splitted_Correct"


"ThisIs_Not_SplittedCorrect" => "This_Is_Not_Splitted_Correct"


"_UnderscoreMarked_Test_Name_" => _Underscore_Marked_Test_Name_"




+ Recent posts