## StartUp Interview Question

• 0

Country: United States
Interview Type: Written Test

Comment hidden because of low score. Click to expand.
0
of 0 vote

can you clarify the question a bit more?

Comment hidden because of low score. Click to expand.
0
of 0 vote

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))``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

This is assuming that all characters are lowercase and ascii.

Create an int array of 26. Create a count int var. Loop through original string array, checking only the first and last letters. Add +1 to the int idex that corresponds with the ascii character code for both first and last letters. Before adding + 1 to character index if current int var is +1 to count, if current value is 1, -1. After looping through original string if count is greater than 0....the strings cannot make a circle. It 0, then they can.

Comment hidden because of low score. Click to expand.
0

Problem with your solution (TheShocker1999) is - as far as I see - is that there might be multiple circles. "aaa" and "bbb" would fulfil your conditions but it would be multiple circles... So you would have to check for that too

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.