Skip to main content

Interview Questions

Review this list of 4,477 interview questions and answers verified by hiring managers and candidates.
  • "bool isConsecutive(int arr[], int n) { // base case if (n max) { max = arr[i]; } } // for an array to contain consecutive integers, the difference between // the maximum and minimum element in it should be exactly \n-1\ if (max - min != n - 1) { return false; } // create an empty set (we can also use a visit"

    Hinata T. - "bool isConsecutive(int arr[], int n) { // base case if (n max) { max = arr[i]; } } // for an array to contain consecutive integers, the difference between // the maximum and minimum element in it should be exactly \n-1\ if (max - min != n - 1) { return false; } // create an empty set (we can also use a visit"See full answer

  • Yahoo logoAsked at Yahoo 
    Add answer
    Frontend Engineer
  • 🧠 Want an expert answer to a question? Saving questions lets us know what content to make next.

  • "362880"

    Kevin Z. - "362880"See full answer

  • "static int countBinaryStrings(int n) { int a[] = new int[n]; int b[] = new int[n]; a[0] = b[0] = 1; for (int i = 1; i < n; i++) { a[i] = a[i - 1] + b[i - 1]; b[i] = a[i - 1]; } System.out.println(a[n - 1] + b[n - 1]); return a[n - 1] + b[n - 1]; }"

    Fakhri A. - "static int countBinaryStrings(int n) { int a[] = new int[n]; int b[] = new int[n]; a[0] = b[0] = 1; for (int i = 1; i < n; i++) { a[i] = a[i - 1] + b[i - 1]; b[i] = a[i - 1]; } System.out.println(a[n - 1] + b[n - 1]); return a[n - 1] + b[n - 1]; }"See full answer

  • "static int findLongestRepeatingSubSeq(String str) { int n = str.length(); int dp = new intn+1; for (int i=0; i<=n; i++) for (int j=0; j<=n; j++) dpi = 0; for (int i=1; i<=n; i++) { for (int j=1; j<=n; j++) { if (str.charAt(i-1)== str.charAt(j-1) && i != j) dpi =  1 + dpi-1; else dpi = Math.max(dpi, dpi-1); } } `return"

    Padmanaban M. - "static int findLongestRepeatingSubSeq(String str) { int n = str.length(); int dp = new intn+1; for (int i=0; i<=n; i++) for (int j=0; j<=n; j++) dpi = 0; for (int i=1; i<=n; i++) { for (int j=1; j<=n; j++) { if (str.charAt(i-1)== str.charAt(j-1) && i != j) dpi =  1 + dpi-1; else dpi = Math.max(dpi, dpi-1); } } `return"See full answer

  • Adobe logoAsked at Adobe 
    9 answers
    +6

    "function isPalindrome(s, start, end) { while (s[start] === s[end] && end >= start) { start++; end--; } return end <= start; } function longestPalindromicSubstring(s) { let longestPalindrome = ''; for (let i=0; i < s.length; i++) { let j = s.length-1; while (s[i] !== s[j] && i <= j) { j--; } if (s[i] === s[j]) { if (isPalindrome(s, i, j)) { const validPalindrome = s.substring(i, j+1"

    Tiago R. - "function isPalindrome(s, start, end) { while (s[start] === s[end] && end >= start) { start++; end--; } return end <= start; } function longestPalindromicSubstring(s) { let longestPalindrome = ''; for (let i=0; i < s.length; i++) { let j = s.length-1; while (s[i] !== s[j] && i <= j) { j--; } if (s[i] === s[j]) { if (isPalindrome(s, i, j)) { const validPalindrome = s.substring(i, j+1"See full answer

    Machine Learning Engineer
    Data Structures & Algorithms
    +3 more
  • Salesforce logoAsked at Salesforce 
    1 answer

    "String commonStr(String str1, String str2) { int len1 = str1.length(); int len2 = str2.length(); if (len1 == 0 || len2 == 0) return ""; // let dpx reprsent the longest common str of 0...x int dp = new int len1 + 1; int maxLen = 0; int endIndex = 0; for (int i = 1; i <= len1; i++) { for (int j = 1; j <= len2; j++) { if (str1.charAt(i-1) == str2.charAt(j-1)) { dpi = dpi-1 + 1; "

    Anonymous Eel - "String commonStr(String str1, String str2) { int len1 = str1.length(); int len2 = str2.length(); if (len1 == 0 || len2 == 0) return ""; // let dpx reprsent the longest common str of 0...x int dp = new int len1 + 1; int maxLen = 0; int endIndex = 0; for (int i = 1; i <= len1; i++) { for (int j = 1; j <= len2; j++) { if (str1.charAt(i-1) == str2.charAt(j-1)) { dpi = dpi-1 + 1; "See full answer

    Software Engineer
    Data Structures & Algorithms
    +1 more
  • Adobe logoAsked at Adobe 
    13 answers
    Video answer for 'Merge k sorted linked lists.'
    +7

    "A much better solution than the one in the article, below: It looks like the ones writing articles here in Javascript do not understand the time/space complexity of javascript methods. shift, splice, sort, etc... In the solution article you have a shift and a sort being done inside a while, that is, the multiplication of Ns. My solution, below, iterates through the list once and then sorts it, separately. It´s O(N+Log(N)) class ListNode { constructor(val = 0, next = null) { th"

    Guilherme F. - "A much better solution than the one in the article, below: It looks like the ones writing articles here in Javascript do not understand the time/space complexity of javascript methods. shift, splice, sort, etc... In the solution article you have a shift and a sort being done inside a while, that is, the multiplication of Ns. My solution, below, iterates through the list once and then sorts it, separately. It´s O(N+Log(N)) class ListNode { constructor(val = 0, next = null) { th"See full answer

    Software Engineer
    Data Structures & Algorithms
    +4 more
  • Meta logoAsked at Meta 
    8 answers
    Video answer for 'Sort a doubly linked list using merge sort.'
    +4

    "function merge(L1, L2) { let L3 = { data: null, next: null }; let prev = L3; while (L1 != null || L2 != null) { if (L1 == null) { prev.next = L2; L2 = L2.next; } else if (L2 == null) { prev.next = L1; L1 = L1.next; } else if (L1.data < L2.data) { prev.next = L1; L1 = L1.next; } else { prev.next = L2; L2 = L2.next; } prev = prev.next; } return L3.next; }"

    Ugo C. - "function merge(L1, L2) { let L3 = { data: null, next: null }; let prev = L3; while (L1 != null || L2 != null) { if (L1 == null) { prev.next = L2; L2 = L2.next; } else if (L2 == null) { prev.next = L1; L1 = L1.next; } else if (L1.data < L2.data) { prev.next = L1; L1 = L1.next; } else { prev.next = L2; L2 = L2.next; } prev = prev.next; } return L3.next; }"See full answer

    Data Structures & Algorithms
    Coding
    +1 more
  • Meta logoAsked at Meta 
    1 answer

    "if decreasing arr, start from end and keep checking if next element increases by 1 or not. wherever not, put that value there."

    Rishabh R. - "if decreasing arr, start from end and keep checking if next element increases by 1 or not. wherever not, put that value there."See full answer

    Data Structures & Algorithms
    Coding
    +1 more
  • Adobe logoAsked at Adobe 
    53 answers
    +49

    "from typing import List def two_sum(nums: List[int], target: int) -> List[int]: prevMap = {} for i, n in enumerate(nums): diff = target - n if diff in prevMap: return [prevMap[diff], i] else: prevMap[n] = i return [] debug your code below print(two_sum([2, 7, 11, 15], 9)) `"

    Anonymous Roadrunner - "from typing import List def two_sum(nums: List[int], target: int) -> List[int]: prevMap = {} for i, n in enumerate(nums): diff = target - n if diff in prevMap: return [prevMap[diff], i] else: prevMap[n] = i return [] debug your code below print(two_sum([2, 7, 11, 15], 9)) `"See full answer

    Software Engineer
    Data Structures & Algorithms
    +5 more
  • LinkedIn logoAsked at LinkedIn 
    1 answer

    "Basic Approach As BST inorder traversal will result in a sequence of increasing order. Store that order in a vector and get the k-1 index to get the Kth smallest element, similarly access the N-K+1 th element will be the Kth largest element Time Complexity: O(n) Space Complexity O(n) Space Optimized Approach For Kth smallest , start inorder traversal, and keep a counter, decrement the counter when you access the node element. When the counter turns 0 that elementwill be the Kth smal"

    Saurabh S. - "Basic Approach As BST inorder traversal will result in a sequence of increasing order. Store that order in a vector and get the k-1 index to get the Kth smallest element, similarly access the N-K+1 th element will be the Kth largest element Time Complexity: O(n) Space Complexity O(n) Space Optimized Approach For Kth smallest , start inorder traversal, and keep a counter, decrement the counter when you access the node element. When the counter turns 0 that elementwill be the Kth smal"See full answer

    Data Structures & Algorithms
    Coding
    +1 more
  • LinkedIn logoAsked at LinkedIn 
    1 answer

    "function constructTree(n, matrix) { let parent = []; let child = []; let root = null; for (let i = 0; i < n; i++) { for (let j = 0; j < n; j++) { if (matrixi === 1) { parent.push(i); child.push(j); } } } for (let i = 0; i < n; i++) { if (parent.indexOf(i) === -1) { root = i; } } let node = new Node(root); for (let i = 0; i < n; i++) { if (i !== root) { constructTreeUtil(node, parent[i], child[i]); } } return node; }"

    Ugo C. - "function constructTree(n, matrix) { let parent = []; let child = []; let root = null; for (let i = 0; i < n; i++) { for (let j = 0; j < n; j++) { if (matrixi === 1) { parent.push(i); child.push(j); } } } for (let i = 0; i < n; i++) { if (parent.indexOf(i) === -1) { root = i; } } let node = new Node(root); for (let i = 0; i < n; i++) { if (i !== root) { constructTreeUtil(node, parent[i], child[i]); } } return node; }"See full answer

    Data Structures & Algorithms
    Coding
    +1 more
Showing 3441-3460 of 4477