Goldman Sachs Coding Interview Questions

Review this list of 15 Goldman Sachs coding data scientist interview questions and answers verified by hiring managers and candidates.
  • Goldman Sachs logoAsked at Goldman Sachs 
    Video answer for 'Find the container with the maximum volume of water.'

    "int getMaxWater(vector& nums) { int n = nums.size(); int mx = INT_MIN; int i=0, j=n-1; while(i<j) { int water = (j - i) * min(nums[i], nums[j]); mx = max(mx, water); if(nums[i] < nums[j]){ i++; } else { j--; } } return mx; } `"

    Richard W. - "int getMaxWater(vector& nums) { int n = nums.size(); int mx = INT_MIN; int i=0, j=n-1; while(i<j) { int water = (j - i) * min(nums[i], nums[j]); mx = max(mx, water); if(nums[i] < nums[j]){ i++; } else { j--; } } return mx; } `"See full answer

    Data Scientist
    Coding
    +3 more
  • Goldman Sachs logoAsked at Goldman Sachs 
    +27

    "public static boolean isPalindrome(String str){ boolean flag = true; int len = str.length()-1; int j = len; for(int i=0;i<=len/2;i++){ if(str.charAt(i)!=str.charAt(j--)){ flag = false; break; } } return flag; }"

    Sravanthi M. - "public static boolean isPalindrome(String str){ boolean flag = true; int len = str.length()-1; int j = len; for(int i=0;i<=len/2;i++){ if(str.charAt(i)!=str.charAt(j--)){ flag = false; break; } } return flag; }"See full answer

    Data Scientist
    Coding
    +4 more
  • " Compare alternate houses i.e for each house starting from the third, calculate the maximum money that can be stolen up to that house by choosing between: Skipping the current house and taking the maximum money stolen up to the previous house. Robbing the current house and adding its value to the maximum money stolen up to the house two steps back. package main import ( "fmt" ) // rob function calculates the maximum money a robber can steal func maxRob(nums []int) int { ln"

    VContaineers - " Compare alternate houses i.e for each house starting from the third, calculate the maximum money that can be stolen up to that house by choosing between: Skipping the current house and taking the maximum money stolen up to the previous house. Robbing the current house and adding its value to the maximum money stolen up to the house two steps back. package main import ( "fmt" ) // rob function calculates the maximum money a robber can steal func maxRob(nums []int) int { ln"See full answer

    Data Scientist
    Coding
    +4 more
  • Goldman Sachs logoAsked at Goldman Sachs 
    +16

    "We can use dictionary to store cache items so that our read / write operations will be O(1). Each time we read or update an existing record, we have to ensure the item is moved to the back of the cache. This will allow us to evict the first item in the cache whenever the cache is full and we need to add new records also making our eviction O(1) Instead of normal dictionary, we will use ordered dictionary to store cache items. This will allow us to efficiently move items to back of the cache a"

    Alfred O. - "We can use dictionary to store cache items so that our read / write operations will be O(1). Each time we read or update an existing record, we have to ensure the item is moved to the back of the cache. This will allow us to evict the first item in the cache whenever the cache is full and we need to add new records also making our eviction O(1) Instead of normal dictionary, we will use ordered dictionary to store cache items. This will allow us to efficiently move items to back of the cache a"See full answer

    Data Scientist
    Coding
    +6 more
  • Goldman Sachs logoAsked at Goldman Sachs 

    "Use a representative of each, e.g. sort the string and add it to the value of a hashmap> where we put all the words that belong to the same anagram together."

    Gaston B. - "Use a representative of each, e.g. sort the string and add it to the value of a hashmap> where we put all the words that belong to the same anagram together."See full answer

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

  • +9

    "Would be better to adjust resolution in the video player directly."

    Anonymous Prawn - "Would be better to adjust resolution in the video player directly."See full answer

    Data Scientist
    Coding
    +4 more
  • Goldman Sachs logoAsked at Goldman Sachs 
    +15

    " def is_valid(s: str) -> bool: openBracket = set() openBracket.add('{') openBracket.add('(') openBracket.add('[') stack = [] for c in s: if stack and (c == ')' and stack[len(stack)-1] == '(')\ or\ (c == '}' and stack[len(stack)-1] == '{')\ or\ (c == ']' and stack[len(stack)-1] == '['): stack.pop() elif c in openBracket: stack.append(c) else: retu"

    Aikya S. - " def is_valid(s: str) -> bool: openBracket = set() openBracket.add('{') openBracket.add('(') openBracket.add('[') stack = [] for c in s: if stack and (c == ')' and stack[len(stack)-1] == '(')\ or\ (c == '}' and stack[len(stack)-1] == '{')\ or\ (c == ']' and stack[len(stack)-1] == '['): stack.pop() elif c in openBracket: stack.append(c) else: retu"See full answer

    Data Scientist
    Coding
    +4 more
  • Goldman Sachs logoAsked at Goldman Sachs 
    Video answer for 'Find the median of two sorted arrays.'
    Data Scientist
    Coding
    +4 more
  • Goldman Sachs logoAsked at Goldman Sachs 
    +6

    " function climbStairs(n) { // 4 iterations of Dynamic Programming solutions: // Step 1: Recursive: // if (n <= 2) return n // return climbStairs(n-1) + climbStairs(n-2) // Step 2: Top-down Memoization // const memo = {0:0, 1:1, 2:2} // function f(x) { // if (x in memo) return memo[x] // memo[x] = f(x-1) + f(x-2) // return memo[x] // } // return f(n) // Step 3: Bottom-up Tabulation // const tab = [0,1,2] // f"

    Matthew K. - " function climbStairs(n) { // 4 iterations of Dynamic Programming solutions: // Step 1: Recursive: // if (n <= 2) return n // return climbStairs(n-1) + climbStairs(n-2) // Step 2: Top-down Memoization // const memo = {0:0, 1:1, 2:2} // function f(x) { // if (x in memo) return memo[x] // memo[x] = f(x-1) + f(x-2) // return memo[x] // } // return f(n) // Step 3: Bottom-up Tabulation // const tab = [0,1,2] // f"See full answer

    Data Scientist
    Coding
    +3 more
  • Goldman Sachs logoAsked at Goldman Sachs 
    Video answer for 'Given the root of a binary tree of integers, return the maximum path sum.'

    "\# Definition for a binary tree node. class TreeNode: def init(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right class Solution: def maxPathSum(self, root: TreeNode) -> int: self.max_sum = float('-inf')"

    Jerry O. - "\# Definition for a binary tree node. class TreeNode: def init(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right class Solution: def maxPathSum(self, root: TreeNode) -> int: self.max_sum = float('-inf')"See full answer

    Data Scientist
    Coding
    +4 more
  • Data Scientist
    Coding
    +4 more
  • Goldman Sachs logoAsked at Goldman Sachs 
    +9

    " class ListNode: def init(self, val=0, next=None): self.val = val self.next = next def has_cycle(head: ListNode) -> bool: pass # your code goes here if head is None: return False previousNodes = set() iter = head while iter: if iter.val in previousNodes: return True previousNodes.add(iter.val) iter = iter.next; return False debug your code below node1 = ListNode(1) node2 = ListNode(2) n"

    Cagdas A. - " class ListNode: def init(self, val=0, next=None): self.val = val self.next = next def has_cycle(head: ListNode) -> bool: pass # your code goes here if head is None: return False previousNodes = set() iter = head while iter: if iter.val in previousNodes: return True previousNodes.add(iter.val) iter = iter.next; return False debug your code below node1 = ListNode(1) node2 = ListNode(2) n"See full answer

    Data Scientist
    Coding
    +4 more
  • Goldman Sachs logoAsked at Goldman Sachs 
    +37

    "function twoSum(nums, target) { let complements = new Map(); for (let i = 0; i < nums.length; i++) { let diff = target - nums[i]; if (complements.has(diff)) { return [complements.get(diff), i]; } complements.set(nums[i], i); } return []; } console.log(twoSum([2, 7, 11, 15], 9)); `"

    Jean-pierre C. - "function twoSum(nums, target) { let complements = new Map(); for (let i = 0; i < nums.length; i++) { let diff = target - nums[i]; if (complements.has(diff)) { return [complements.get(diff), i]; } complements.set(nums[i], i); } return []; } console.log(twoSum([2, 7, 11, 15], 9)); `"See full answer

    Data Scientist
    Coding
    +5 more
  • Goldman Sachs logoAsked at Goldman Sachs 
    Data Scientist
    Coding
    +4 more
  • Goldman Sachs logoAsked at Goldman Sachs 
    +7

    "def traprainwater(height: List[int]) -> int: n = len(height) totalwaterlevel = 0 for i in range(n): j = i+1 while j = n: break rows = j - i -1 intrwaterlevel = min(height[j], height[i]) * rows for k in range(i+1, j): intrwaterlevel -= height[k] totalwaterlevel += intrwaterlevel i = j return totalwaterlevel"

    Manoj R. - "def traprainwater(height: List[int]) -> int: n = len(height) totalwaterlevel = 0 for i in range(n): j = i+1 while j = n: break rows = j - i -1 intrwaterlevel = min(height[j], height[i]) * rows for k in range(i+1, j): intrwaterlevel -= height[k] totalwaterlevel += intrwaterlevel i = j return totalwaterlevel"See full answer

    Data Scientist
    Coding
    +4 more
Showing 1-15 of 15