Software Engineer Data Structures & Algorithms Interview Questions

Review this list of 172 data structures & algorithms software engineer interview questions and answers verified by hiring managers and candidates.
  • Apple logoAsked at Apple 
    +2

    "Make current as root. 2 while current is not null, if p and q are less than current, go left. If p and q are greater than current, go right. else return current. return null"

    Vaibhav D. - "Make current as root. 2 while current is not null, if p and q are less than current, go left. If p and q are greater than current, go right. else return current. return null"See full answer

    Software Engineer
    Data Structures & Algorithms
    +4 more
  • "import java.util.*; public class NetworkTopology { public int topologytype(int N, int M, int[] input3, int[] input4) { if (M != N - 1 && M != N) return -1; // Fast check for invalid cases int[] degree = new int[N + 1]; // Degree of each node (1-based indexing) // Build the degree array for (int i = 0; i < M; i++) { degree[input3[i]]++; degree[input4[i]]++; } // Check for Bus Topology boolean isBus = (M"

    Alessandro R. - "import java.util.*; public class NetworkTopology { public int topologytype(int N, int M, int[] input3, int[] input4) { if (M != N - 1 && M != N) return -1; // Fast check for invalid cases int[] degree = new int[N + 1]; // Degree of each node (1-based indexing) // Build the degree array for (int i = 0; i < M; i++) { degree[input3[i]]++; degree[input4[i]]++; } // Check for Bus Topology boolean isBus = (M"See full answer

    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Apple logoAsked at Apple 
    Software Engineer
    Data Structures & Algorithms
    +1 more
  • "int a_array[10] = {3,6,4,7,2,1,9}; int index = 0; int index2 = 0; for ( index = 0; index < sizeof(a_array); index++ ) { int tmpindex = index + 1; if ( tmpindex <= sizeof(a_array) ) { for ( index2 = tmpindex; index2 < sizeof(a_array); index2++ ) { if ( aarray[index] <= aarray[index2] ) { print( "%d is the NGE of %d" array[index2], array[index]); break; "

    Mark S. - "int a_array[10] = {3,6,4,7,2,1,9}; int index = 0; int index2 = 0; for ( index = 0; index < sizeof(a_array); index++ ) { int tmpindex = index + 1; if ( tmpindex <= sizeof(a_array) ) { for ( index2 = tmpindex; index2 < sizeof(a_array); index2++ ) { if ( aarray[index] <= aarray[index2] ) { print( "%d is the NGE of %d" array[index2], array[index]); break; "See full answer

    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Snap logoAsked at Snap 

    "public Double calculateRatio(String source, String destination) { Double ratio=1.0; while(graph.containsKey(source) && !visited.contains(source)) { visited.add(source); Map valueMap=graph.get(source); if(valueMap.containsKey(destination)) { return ratio*=valueMap.get(destination); } Map.Entry firstEntry=valueMap.entrySet().iterator().next(); source=firstEntry.getKey(); ratio*=firstEntry.getValue(); System.out.println("Entered"); } return null; }"

    Divya R. - "public Double calculateRatio(String source, String destination) { Double ratio=1.0; while(graph.containsKey(source) && !visited.contains(source)) { visited.add(source); Map valueMap=graph.get(source); if(valueMap.containsKey(destination)) { return ratio*=valueMap.get(destination); } Map.Entry firstEntry=valueMap.entrySet().iterator().next(); source=firstEntry.getKey(); ratio*=firstEntry.getValue(); System.out.println("Entered"); } return null; }"See full answer

    Software Engineer
    Data Structures & Algorithms
    +2 more
  • 🧠 Want an expert answer to a question? Saving questions lets us know what content to make next.

  • "I first asked few clarifying questions like the return array may need not contain the list of building in the same order, to which the interviewer agreed. Then I came up with an approach where we iterate the array from right to left and keep a max variable which will keep the value of the current max. When we find an item which is greater than max we update the max and add this element into our solution. The interviewer agreed for the approach. I discussed few corner scenarios with the interview"

    Rishabh N. - "I first asked few clarifying questions like the return array may need not contain the list of building in the same order, to which the interviewer agreed. Then I came up with an approach where we iterate the array from right to left and keep a max variable which will keep the value of the current max. When we find an item which is greater than max we update the max and add this element into our solution. The interviewer agreed for the approach. I discussed few corner scenarios with the interview"See full answer

    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Software Engineer
    Data Structures & Algorithms
    +1 more
  • Adobe logoAsked at Adobe 

    "Leetcode 347: Heap + Hashtable Follow up question: create heap with the length of K instead of N (more time complexity but less space )"

    Chen J. - "Leetcode 347: Heap + Hashtable Follow up question: create heap with the length of K instead of N (more time complexity but less space )"See full answer

    Software Engineer
    Data Structures & Algorithms
    +3 more
  • Apple logoAsked at Apple 

    "Function that transforms each elements in a collection and returns new collection with transformed elements"

    Susmita S. - "Function that transforms each elements in a collection and returns new collection with transformed elements"See full answer

    Software Engineer
    Data Structures & Algorithms
    +1 more
  • JP Morgan Chase logoAsked at JP Morgan Chase 
    Software Engineer
    Data Structures & Algorithms
    +1 more
  • "I try to solve this initially using quick select where will take a pivot element and position the remaining elements and check if the current index is answer or not and continue the same but it requires o(n*n), but interviewee is expecting the best from me, so at the end i tried solving using heaps where will check the difference between k and n-k to use min or max heap after that we will heap the array, and will keep popping the element k-1 and return the peek one which leads to answer."

    Mourya C. - "I try to solve this initially using quick select where will take a pivot element and position the remaining elements and check if the current index is answer or not and continue the same but it requires o(n*n), but interviewee is expecting the best from me, so at the end i tried solving using heaps where will check the difference between k and n-k to use min or max heap after that we will heap the array, and will keep popping the element k-1 and return the peek one which leads to answer."See full answer

    Software Engineer
    Data Structures & Algorithms
    +2 more
  • LinkedIn logoAsked at LinkedIn 
    Software Engineer
    Data Structures & Algorithms
    +2 more
  • Apple logoAsked at Apple 
    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Apple logoAsked at Apple 
    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Apple logoAsked at Apple 

    "filter function usually exists in some high level programming that adopt FP paradigm. It taks a sequence of items and a predicate function, and returns (conceptually) a subset of the items that satisfy the predicate. Adopt this kind of operation (filter, map, reduce, take, pairwise ...) can help writting cleaner code, and reduce the usage of mutable part in the program, lower the possibility of making human mistake. Take Python for example (although const-ness is not exists in Python), assu"

    Weida H. - "filter function usually exists in some high level programming that adopt FP paradigm. It taks a sequence of items and a predicate function, and returns (conceptually) a subset of the items that satisfy the predicate. Adopt this kind of operation (filter, map, reduce, take, pairwise ...) can help writting cleaner code, and reduce the usage of mutable part in the program, lower the possibility of making human mistake. Take Python for example (although const-ness is not exists in Python), assu"See full answer

    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Apple logoAsked at Apple 
    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Apple logoAsked at Apple 
    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Apple logoAsked at Apple 
    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Andela logoAsked at Andela 

    "let str = 'this is a test of programs'; let obj={}; for (let s of str ) obj[s]?(obj[s]=obj[s]+1):(obj[s]=1) console.log(JSON.stringify(obj))"

    Anonymous Emu - "let str = 'this is a test of programs'; let obj={}; for (let s of str ) obj[s]?(obj[s]=obj[s]+1):(obj[s]=1) console.log(JSON.stringify(obj))"See full answer

    Software Engineer
    Data Structures & Algorithms
    +2 more
  • Adobe logoAsked at Adobe 

    "#include #include #include using namespace std; void printComs(int prev, int start, int end, int target) { if (start >= end) return; while (start target) { end--; } else { st"

    Iris F. - "#include #include #include using namespace std; void printComs(int prev, int start, int end, int target) { if (start >= end) return; while (start target) { end--; } else { st"See full answer

    Software Engineer
    Data Structures & Algorithms
    +4 more
Showing 141-160 of 172