#64 Strip Comments


Complete the solution so that it strips all text that follows any of a set of comment markers passed in. Any whitespace at the end of the line should also be stripped out.


Example:


Given an input string of:


apples, pears # and bananas

grapes

bananas !apples

The output expected would be:


apples, pears

grapes

bananas

The code would be called like so:


var result = solution("apples, pears # and bananas\ngrapes\nbananas !apples", ["#", "!"])

// result should == "apples, pears\ngrapes\nbananas"




 #63 Sort two arrays


When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said


Description:

Give you two arrays arr1 and arr2. They have the same length(length>=2). The elements of two arrays always be integer.


Sort arr1 according to the ascending order of arr2; Sort arr2 according to the ascending order of arr1. Description is not easy to understand, for example:


 arr1=[5,4,3,2,1], 

 arr2=[6,5,7,8,9]

Let us try to sorting arr1. First, we need know the ascending order of arr2:


 [5,6,7,8,9]

We can see, after sort arr2 to ascending order, some elements' index are changed:


 unsort arr2      ascending order arr2

 [6,5,7,8,9]--->      [5,6,7,8,9]


 index0(6)  --->      index1

 index1(5)  --->      index0

 index2(7)            index2(no change)

 index3(8)            index3(no change)

 index4(9)            index4(no change)

So, wo need according to these changes to sorting arr1:


 unsort arr1          sorted arr1

 [5,4,3,2,1]--->      [4,5,3,2,1]


 index0(5)  --->      index1

 index1(4)  --->      index0

 index2(3)            index2(no change)

 index3(2)            index3(no change)

 index4(1)            index4(no change)


 So: sorted arr1= [4,5,3,2,1]

And then, we sorting arr2 with the same process:


 unsort arr1      ascending order arr1

 [5,4,3,2,1]--->      [1,2,3,4,5]


 index0(5)  --->      index4

 index1(4)  --->      index3

 index2(3)            index2(no change)

 index3(2)  --->      index1

 index4(1)  --->      index0


 unsort arr2          sorted arr2

 [6,5,7,8,9]--->      [9,8,7,5,6]


 index0(6)  --->      index4

 index1(5)  --->      index3

 index2(7)            index2(no change)

 index3(8)  --->      index1

 index4(9)  --->      index0


 So: sorted arr2= [9,8,7,5,6]

Finally, returns the sorted arrays by a 2D array: [sorted arr1, sorted arr2]


Note: In ascending order sorting process(not the final sort), if some elements have same value, sort them according to their index; You can modify the original array, but I advise you not to do that. ;-)


Some Examples and explain

sortArrays([5,4,3,2,1],[6,5,7,8,9]) should return

[[4,5,3,2,1],[9,8,7,5,6]]


sortArrays([2,1,3,4,5],[5,6,7,8,9]) should return

[[2,1,3,4,5],[6,5,7,8,9]]


sortArrays([5,6,9,2,6,5],[3,6,7,4,8,1]) should return

[[5,5,2,6,9,6],[4,3,1,6,8,7]]




#62 Simple Pig Latin


 to the end of it, then add "ay" to the end of the word. Leave punctuation marks untouched.


Examples

pigIt('Pig latin is cool'); // igPay atinlay siay oolcay

pigIt('Hello world !');     // elloHay orldWay !



#61 Build a pile of Cubes 


Your task is to construct a building which will be a pile of n cubes. The cube at the bottom will have a volume of n^3, the cube above will have volume of (n-1)^3 and so on until the top which will have a volume of 1^3.


You are given the total volume m of the building. Being given m can you find the number n of cubes you will have to build?


The parameter of the function findNb (find_nb, find-nb, findNb) will be an integer m and you have to return the integer n such as n^3 + (n-1)^3 + ... + 1^3 = m if such a n exists or -1 if there is no such n.


Examples:

findNb(1071225) --> 45

findNb(91716553919377) --> -1




#60 Two Sum


Write a function that takes an array of numbers (integers for the tests) and a target number. It should find two different items in the array that, when added together, give the target value. The indices of these items should then be returned in an array like so: [index1, index2].


For the purposes of this kata, some tests may have multiple answers; any valid solutions will be accepted.


The input will always be valid 

(numbers will be an array of length 2 or greater, and all of the items will be numbers; target will always be the sum of two different items from that array).



public class Solution
{
    public static int[] twoSum(final int[] numbers, int target)
    {
      for(int i = 0; i < numbers.length;i++ ) {
        for(int j = i + 1; j < numbers.length;j++) {
          if(numbers[i] + numbers[j] == target) {
              return new int []{i,j};
            }
          }
        }
        return null; // Do your magic!
    }
}

 #59 How long is the cable?


The goal is to calculate the length of a cable.


The cable will be symbolized with a combination of the following characters: -, _, =.


Each character has a different length: - is of length 1, _ of length 2 and = of length 3.


Sometimes the cable is making a loop. This will be symbolized with brackets.


When you have reached a closing bracket ), you have to go back to the corresponding opening bracket and count the length again -> this represents a loop.


For example:


Cable.calculateLength("----"); // => 4

Cable.calculateLength("_(-_)"); // => 8 --> _-_-_

Cable.calculateLength("_(-(_))="); // => 15 --> _(-__)= --> _-__-__=

If a cable is broken, meaning number of ( is not equal to number of ), you must throw a BracketException of type RuntimeException that you must implement yourself.


If the cable has a node, meaning a different character is detected on the input string, throw a NodeException of type RuntimeException (implement it as well)


If a cable is both broken and contains nodes then it should throw the exception that can be first detected and confirmed.


Good luck and keep an eye on the performance of your code - suboptimal solutions may time out in the Submit tests ;)



#58 My Languages 


Your task


Given a list of languages and your respective test results, return the list of languages where your test score is at least 60, in descending order of the results.


Note: There will be no duplicate values.


Examples

{"Java" => 10, "Ruby" => 80, "Python" => 65}  --> ["Ruby", "Python"]

{"Hindi" => 60, "Dutch" => 93, "Greek" => 71} --> ["Dutch", "Greek", "Hindi"]

{"C++" => 50, "ASM" => 10, "Haskell" => 20}   --> []




#57 Frequency Analysis With Buckets


Description:


Given an input array (arr) of positive integers, the objective is to return an output array where each index represents the amount of times an element appeared (frequency) in the input array.


More specifically, the element at each index of the output array will be an array (bucket) containing integers that appeared index-amount-of-times.


Otherwise, slot nulls (JavaScript, Java), nils (Ruby), or NULL's (C/C++) where appropriate. A valid array will always be provided.


If an array of [1,2,3,4,4,5,5,5] is passed in, the expected output should be: [null, [1,2,3], [4], [5], null, null, null, null, null].


Explanation:


// bucketize(arr) ======> outputArray

bucketize({1,2,3,4,4,5,5,5}) ======> {null, {1,2,3}, {4}, {5}, null, null, null, null, null}

An element cannot appear 0 times, so a null is placed at outputArray[0]. The elements 1, 2, and 3 appear once. This is why they are located at outputArray[1]. Notice the elements are grouped together in an array and sorted in ascending order. The element 4 appears twice. This is why it is located at outputArray[2]. The element 5 appears three times. This is why it is located at outputArray[3].


Although an integer could have possibly appeared four, five, six, seven, or eight times, this is not the case for this particular example. This is the reason why the elements at outputArray[4], outputArray[5], outputArray[6], outputArray[7], and outputArray[8] are all null values.


Examples:


bucketize({2,2,4,4,6,6,9,9,9,9}) ===> {null, null, {2,4,6}, null, {9}, null, null, null, null, null, null};

bucketize({3,3,3,3,2}) =============> {null, {2}, null, null, {3}, null};

bucketize({5,5,5,5,5}) =============> {null, null, null, null, null, {5}};

bucketize({77,3,40,40,40}) =========> {null, {3,77}, null, {40}, null, null};

bucketize({16,7,5,3,6,23}) =========> {null, {3,5,6,7,16,23}, null, null, null, null, null};



 #56 Maximum subarray sum


The maximum sum subarray problem consists in finding the maximum sum of a contiguous subsequence in an array or list of integers:


Max.sequence(new int[]{-2, 1, -3, 4, -1, 2, 1, -5, 4});

// should be 6: {4, -1, 2, 1}

Easy case is when the list is made up of only positive numbers and the maximum sum is the sum of the whole array. If the list is made up of only negative numbers, return 0 instead.


Empty list is considered to have zero greatest sum. Note that the empty list or array is also a valid sublist/subarray.



#55 Sum of Two Integers



Task

Given Two intgers a , b , find The sum of them , BUT You are not allowed to use the operators + and -


Notes

The numbers (a,b) may be positive , negative values or zeros .


Returning value will be integer .


Javascript: the Array reduce methods are disabled, along with eval, require, and module .


Java: the following methods are prohibited: addExact, average, collect, decrement, increment, nextAfter, nextDown, nextUp, reduce, subtractExact, sum, summing . The following classes are prohibited: BigDecimal and BigInteger .


NASM: the following instructions are prohibited: add, adc, adcx, adox, dec, inc, sbb, sub .


Input >> Output Examples

1- Add (5,19) ==> return (24) 


2- Add (-27,18) ==> return (-9)


3- Add (-14,-16) ==> return (-30)



+ Recent posts