jsduder
BAN USER
- 0of 0 votes
AnswersThis was a javascript interview.
- jsduder in United States
There are two arrays:
var arr1 = [2,"undefined",7,"undefined", 10,"undefined","undefiend"];
var arr2 = [5,8,12,14];
They need to be merged such that arr1=[2,5,7,8,10,12,14]
This needs to be done in place and in constant time.| Report Duplicate | Flag | PURGE
Developer Program Engineer Algorithm - 0of 0 votes
AnswersI was asked this question in an algorithm interview. Since my coding language was javascript I was asked to implement a hashmap n white board with collision detection.
- jsduder in United States
I guess they were looking for a hashing algorithm that will create a linked list in case of a collision and also an equals method| Report Duplicate | Flag | PURGE
StartUp Developer Program Engineer Algorithm - 0of 0 votes
AnswersUsing Javascript write code to detect and remove a loop from a cylic linked list
- jsduder in United States| Report Duplicate | Flag | PURGE
Developer Program Engineer Algorithm - 0of 0 votes
AnswersJavascript check if string can be chained:
- jsduder in United States
Given an array of strings, find if the strings can be chained to form a circle.
Eg:
arr = ["aab", "bac", "aaa", "cda"]
can be chained as "aaa"-> "aab"-> "bbb" -> "baa"
(Each string differs by one letter)| Report Duplicate | Flag | PURGE
StartUp Algorithm - 0of 0 votes
AnswerGiven a string of numbers separated by spaces figure out whether or not you can arrive at 42 with the numbers using only addition, subtraction, and multiplication using java or javascript
- jsduder in United States| Report Duplicate | Flag | PURGE
Service Now Software Developer Algorithm - 0of 0 votes
AnswersCount the Mines Problem:
- jsduder in United States
Your program will first read an integer N from stdin.
Then it will then read N lines of N integers separated by spaces.
Each integer in this Grid will be either 1 or 0.
The program then outputs an N x N Grid where each Grid element represents the number of 1's surrounding that element, (excluding the element itself).
For (column, row) = (0, 0), surrounding element indices are (0,1) (1,0) and (1,1).
Similarly for (1,1), surrounding element indices are (0,0) (0,1) (0,2) (1,0) (1,2) (2,0) (2,1) and (2,2).
Constraints:
Your output lines should not have any trailing or leading white space
Maximum Dimension of Grid = 1000 x 1000
Example Input:
"3 0 1 0 0 0 0 1 0 0"
Expected output:
1 0 1
2 2 1
0 1 0| Report Duplicate | Flag | PURGE
xyz Software Developer Algorithm
Something in these lines:
var arr = ["aab", "bac", "aaa", "cda"];
function wordChaining(arr){
var index = 1;
var arr = arr.sort();
console.log(arr);
var sortedArr = [arr[0]];
var lastchar;
while(index < arr.length){
console.log("arr",arr[index].substring(0,1), arr, arr[index]);
console.log("sorted",sortedArr[index-1].substring(arr[index-1].length-1), sortedArr, sortedArr[index-1])
if(arr[index].substring(0,1)==sortedArr[index-1].substring(sortedArr[index-1].length-1)){
sortedArr.push(arr[index]);
}
index++
}
return (sortedArr.length == arr.length) ? sortedArr : false;
}
console.log(wordChaining(arr))
Something in these lines. But it gives me an incorrect output
var allNodes =[];
function NodeClass(value){
this.value = value;
}
var root = new NodeClass(20);
root.left = new NodeClass(8);
root.right = new NodeClass(22);
root.left.left = new NodeClass(4);
root.left.right = new NodeClass(12);
root.left.right.left = new NodeClass(10);
root.left.right.right = new NodeClass(14);
var target = root.left.right;
function printkdistanceNodeDown(root, k) {
// Base Case
if (root == null || k < 0) return;
// If we reach a k distant node, print it
if (k==0)
{
// console.log(root.value);
allNodes.push(root.value)
return;
}
// Recur for left and right subtrees
printkdistanceNodeDown(root.left, k-1);
printkdistanceNodeDown(root.right, k-1);
}
function printkdistanceNode(root, target , k) {
// Base Case 1: If tree is empty, return -1
if (root == null) return -1;
if (root == target)
{
printkdistanceNodeDown(root, k);
return 0;
}
// Recur for left subtree
var dl = printkdistanceNode(root.left, target, k);
// Check if target node was found in left subtree
if (dl != -1)
{
if (dl + 1 == k){
console.log(root.value);
allNodes.push(root.value);
}
else
printkdistanceNodeDown(root.right, k-dl-2);
return 1 + dl;
}
var dr = printkdistanceNode(root.right, target, k);
if (dr != -1)
{
if (dr + 1 == k){
console.log(root.value);
allNodes.push(root.value);
}
else
printkdistanceNodeDown(root.left, k-dr-2);
return 1 + dr;
}
return -1;
}
console.log(printkdistanceNode(root, target, 2));
function getArrayRange(first, last){
var arrRange =[];
for(var i=first; i<=last; i++){
arrRange.push(i);
}
return arrRange
}
//console.log(getArrayRange(7,21))
function removeSubArr(arr){
var obj = {};
var fullArr = [];
for (var i=0; i<arr.length; i++){
for(var j=0; j<arr[i].length; j++){
fullArr.push(getArrayRange(arr[i][0], arr[i][1]));
obj[arr[i]] = getArrayRange(arr[i][0], arr[i][1]);
}
}
for(var prop in obj){
if(obj.hasOwnProperty(prop)){
for(var i =0; i< fullArr.length; i++){
if(subArrCheck(obj[prop], fullArr[i]) == true){
fullArr.splice(i,1);
}
}
}
}
return fullArr;
}
function subArrCheck(arr, subarr) {
var i, found, j;
for (i = 0; i < 1 + (arr.length - subarr.length); ++i) {
found = true;
for (j = 0; j < subarr.length; ++j) {
if (arr[i + j] !== subarr[j]) {
found = false;
break;
}
}
if (found) return true;
}
return false;
};
console.log(removeSubArr([[2, 6],[3, 5],[7, 21],[20, 21]]));
RepLizzieGibson, Cloud Support Associate at Aspire Systems
I'm an engineering student from Huntsville, AL USA. Have more interest in management and stuff related to business. Promptly ...
This is my code: but it is not working as expected: As in the loop is being detected but I am not able to remove the loop
- jsduder December 01, 2015