devesh chanchlani
BAN USER
There can be 2 approaches. One is to sort each and every word, and form a key for the hash-map.
If sorting each and every word is not an option, then there is a second approach. You can actually form a "hash-key" such that its unique for each set of characters.
findDiffElements = function (arr1, arr2, diffArr){
arr2.sort();
diffArr.sort();
for (var i = 0; i < arr1.length; i++) {
var idx2 = arr2.length - 1;
var idxDiff = 0;
var arr1Elm = arr1[i];
while (idx2 >= 0 && idxDiff < diffArr.length) {
var sum = arr2[idx2] + diffArr[idxDiff];
if(sum === arr1Elm) {
console.log(arr1Elm + '-' + arr2[idx2] + '=' + diffArr[idxDiff]);
idx2--;
} else if(sum > arr1Elm) {
idx2--;
} else {
idxDiff++;
}
}
}
}
I dont think you need these 2 lines:
if (alen == 0) { i = -1; }
if (blen == 0) { i = k-1; }
@Punit, I follow the "syntax". It is so because the question says, you are given a function, and you have to complete it. You are not supposed to change the question !!
- devesh chanchlani May 16, 2012Input to the function should be - Node root, Node start, int k
- devesh chanchlani May 16, 2012inout to the function should be - Node root, Node start, int k
- devesh chanchlani May 16, 2012I guess this would be the initial code fragment provided ...
- devesh chanchlani May 16, 2012The solution in normal JavaScript (can be quickly written on browser, and executed:-), and following Binary Search:
//returns the starting point of an array-segment
var minList = function(arr) {
var len = arr.length;
//checks whether the array-segment is sorted
if(arr[0] <= arr[len-1]) {
return arr[0]; //returns the min value in an array-segment
} else {
//else continue till you find a sorted array segment
var arr2 = arr.splice(arr.length/2);
var min1 = minList(arr);
var min2 = minList(arr2);
return Math.min(min1,min2);
}
};
Just one thing, you need not check where node 'e' points to, as it is the last node.
- devesh chanchlani May 10, 2012
RepSandraGabriel, Analyst at ABC TECH SUPPORT
We Data Entry Operators have a variety of duties, including processing documents, solving inconsistencies, securing information, updating databases and using ...
RepRitterNicole, DIGITAL MARKETING at Arista Networks
I am Ritter, Experimental psychologist refers to work done who apply experimental methods to psychological study and the processes that ...
RepAmaraPerez, Android Engineer at Allegient
I am an outgoing and motivated flight attendant with a strong customer-oriented approach and excellent communication skills.I am always ...
RepEddieCody, abc at A9
I am a creative freelance graphic designer with over 3 years of experience in developing engaging and innovative digital and ...
I don't think using Horner's method will be helpful here. The reason being, it will generate different hash-key values for anagrams, ie 'abcd' and 'bacd' will have different hash-key values.
A simple hash function could be adding squares of all ascii values of the characters.
- devesh chanchlani May 28, 2012