Interview Questions

Review this list of 3,949 interview questions and answers verified by hiring managers and candidates.
  • "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 
    +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

    Data Engineer
    Data Structures & Algorithms
    +3 more
  • Salesforce logoAsked at Salesforce 

    "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; "

    Emma X. - "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
    Coding
    +1 more
  • Adobe logoAsked at Adobe 
    Video answer for 'Merge k sorted linked lists.'
    +6

    "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 (Facebook) logoAsked at Meta (Facebook) 
    Video answer for 'Sort a doubly linked list using merge sort.'
    +4

    "arr1.append(arr2); arr1.sort();"

    Gennady O. - "arr1.append(arr2); arr1.sort();"See full answer

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

  • Meta (Facebook) logoAsked at Meta (Facebook) 

    "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 
    +37

    " Brute Force Two Pointer Solution: from typing import List def two_sum(nums, target): for i in range(len(nums)): for j in range(i+1, len(nums)): if nums[i]+nums[j]==target: return [i,j] return [] debug your code below print(two_sum([2, 7, 11, 15], 9)) `"

    Ritaban M. - " Brute Force Two Pointer Solution: from typing import List def two_sum(nums, target): for i in range(len(nums)): for j in range(i+1, len(nums)): if nums[i]+nums[j]==target: return [i,j] return [] debug your code below print(two_sum([2, 7, 11, 15], 9)) `"See full answer

    Software Engineer
    Data Structures & Algorithms
    +5 more
  • "// Function to delete a node from BST. public static Node deleteNode(Node root, int X) { // code here. if(root == null) return root; if(X root.data){ root.right = deleteNode(root.right, X); return root; } if(root.left == null){ return root.right; }else if(root.right == null){ "

    Vipin G. - "// Function to delete a node from BST. public static Node deleteNode(Node root, int X) { // code here. if(root == null) return root; if(X root.data){ root.right = deleteNode(root.right, X); return root; } if(root.left == null){ return root.right; }else if(root.right == null){ "See full answer

    Technical
  • LinkedIn logoAsked at LinkedIn 

    "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

    Coding
    Data Structures & Algorithms
    +1 more
  • Adobe logoAsked at Adobe 
    +5

    "bool isValidBST(TreeNode* root, long min = LONGMIN, long max = LONGMAX){ if (root == NULL) return true; if (root->val val >= max) return false; return isValidBST(root->left, min, root->val) && isValidBST(root->right, root->val, max); } `"

    Alvaro R. - "bool isValidBST(TreeNode* root, long min = LONGMIN, long max = LONGMAX){ if (root == NULL) return true; if (root->val val >= max) return false; return isValidBST(root->left, min, root->val) && isValidBST(root->right, root->val, max); } `"See full answer

    Data Engineer
    Coding
    +4 more
  • "Recursively get the left height and right height of the sub-tree, and then check if it is balanced at this node, return false."

    Nishant R. - "Recursively get the left height and right height of the sub-tree, and then check if it is balanced at this node, return false."See full answer

  • 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
  • Google logoAsked at Google 
    Software Engineer
  • Apple logoAsked at Apple 

    "The height of a binary tree is the maximum number of edges from the root node to any leaf node. To calculate the height of a binary tree, we can use a recursive approach. The basic idea is to compare the heights of the left and right subtrees of the root node, and return the maximum of them plus one."

    Prashant Y. - "The height of a binary tree is the maximum number of edges from the root node to any leaf node. To calculate the height of a binary tree, we can use a recursive approach. The basic idea is to compare the heights of the left and right subtrees of the root node, and return the maximum of them plus one."See full answer

    Machine Learning Engineer
    Data Structures & Algorithms
    +3 more
  • "class Node { int val; Node left, right; Node(int v) { val = v; left = right = null; } } class BinaryTree { Node root1, root2; boolean identicalTrees(Node a, Node b) { if (a == null && b == null) return true; if (a != null && b != null) return (a.val == b.val && identicalTrees(a.left, b.left) && identicalTrees(a.right, b.right)); "

    Tushar A. - "class Node { int val; Node left, right; Node(int v) { val = v; left = right = null; } } class BinaryTree { Node root1, root2; boolean identicalTrees(Node a, Node b) { if (a == null && b == null) return true; if (a != null && b != null) return (a.val == b.val && identicalTrees(a.left, b.left) && identicalTrees(a.right, b.right)); "See full answer

    Coding
    Data Structures & Algorithms
  • +1

    "You may backtracking it but I don't see what relation this matrix represents?"

    Denis F. - "You may backtracking it but I don't see what relation this matrix represents?"See full answer

Showing 2921-2940 of 3949