Solutions engineer Interview Questions | Glassdoor

# Solutions engineer Interview Questions

1,023

solutions engineer interview questions shared by candidates

## Top Interview Questions

Sort: RelevancePopular Date

Dec 8, 2015
 Given a list of integers and a target number, list all pairs that sum up to that number9 AnswersCould you describe the onsite rounds a little bit more in detail please?? Thank you.Could you manage it properly?I can think of two solutions, one without additional memory and other with additional memory. First: With additional memory using a hash table. Just traverse the array. At each value see if target-value is in the hashtable, if it is print it, else insert the value to the hashtable. Just in one pass you can find the pair. This also prevents writing (a,b) and (b,a) which is essentially same two times. int main (int argc, char * argv[]) { vector v = {2, 3, 5, 1, 6, 9, 10}; int target = 12; map m; for(auto it = v.begin(); it!= v.end(); it++) { int diff = target - *it; if(m.find(diff) != m.end()) { cout v = {2, 3, 5, 1, 6, 9, 10}; int target = 12; std::sort(v.begin(), v.end()); int left = 0; int right = (int)v.size()-1; while(left < right) { if(v[left] + v[right] == target) { cout << v[left] << " ," << v[right] << "\n"; left++; right--; } else if (v[left] + v[right] < target) left++; else right--; } return 0; }Show More ResponsesNot sure what happened above an wrong code got pasted. First one: int main (int argc, char * argv[]) { vector v = {2, 3, 5, 1, 6, 9, 10}; int target = 12; map m; for(auto it = v.begin(); it!= v.end(); it++) { int diff = target - *it; if(m.find(diff) != m.end()) { cout v = {2, 3, 5, 1, 6, 9, 10}; int target = 6; unordered_map m; //essentially a hash table map used; //to make sure we do not print same pair twice as (a,b) and (b,a) for(auto it = v.begin(); it!= v.end(); it++) //just load from vector to hashtable for quick lookup. m[*it]++; for(auto it = v.begin(); it!= v.end(); it++) { int diff = target - *it; auto it2 = m.find(diff); if(it2 != m.end()) { if(used.find(diff) == used.end() && used.find(*it) == used.end()){ //use unused pair cout << *it << ", " << diff << "\n" ; used[diff]++; used[*it]++; } } } return 0; }WTH. Something wrong with the interface, I will post one by one. int main (int argc, char * argv[]) { vector v = {2, 3, 5, 1, 6, 9, 10}; int target = 12; map m; for(auto it = v.begin(); it!= v.end(); it++) { int diff = target - *it; if(m.find(diff) != m.end()) { cout << *it << " ," << diff << "\n"; } else{ m[*it]++; } } return 0; }I think the solution to this problem is pretty easy. We need to take a map that monitors for the difference in it. I got the following code for it: int[] findPairs(int[] numbers, int target){ Map map = new HashMap(); int[] result = new int; for(int i=0;iI am considering that the above solution is a List of List of integer pairs. Also, I am considering that pair (5,2) and (2,5) are different and are allowed in the solution set. I got the following solution from the problem posted and making the above assumptions. List> findTarget(int[] arr, int target){ List> result = new ArrayList>(); Set set = new HashSet(); for(int i=0;i temp = new ArrayList(); temp.add(target-arr[i]); temp.add(arr[i]); result.add(temp); } set.add(arr[i]); } return result; }Isn't this famous 2 sum problem?here is my C# solution: class PairSums { static void Main(string[] args) { // Call numberOfWays() with test cases here int ans = numberOfWays(new int[] { 2, 1, 3, 4, 4, 2, 2 }, 6); Console.WriteLine(ans); } private static int numberOfWays(int[] arr, int k) { Dictionary map = new Dictionary(); for (int i = 0; i distinct = map.Keys.ToList(); distinct.Sort(); int sum = 0; foreach (int i in distinct) { int target = k - i; if (map.ContainsKey(target) && i != target) { sum += map[i] * map[target]; } } sum = sum / 2; if (k % 2 == 0 && map.ContainsKey(k / 2)) { int count = map[k / 2]; sum += factorial(count) / (factorial(count - 2) * 2); } return sum; } private static int factorial(int x) { int product = 1; while (x > 1) { product *= x; x--; } return product; } }

Sep 17, 2019
 What port does ftp use? (That seemed like a trick question because they only wanted one port)6 Answers20 and 21 but they only wanted 20.20 for TCP; 21 on command20 is for ftp and 21 is often used for ftps, i think.Show More ResponsesIn FTP, Port 20 is used for the data whilst port 21 is used for commandsPort numbers 21 and 20 are used for FTP. Port 21 is used to establish the connection between the 2 computers and port 20 to transfer data.20 (data) & 21 (commands) for regular ftp, 989 (data) & 990 (commands) for ftps. not sure why they want 20 though since the first connection is typically established on 21, unless they're specifically troubleshooting why data isn't being transferred

Jun 19, 2015

Jul 17, 2015
 Write a program which stores the results of the numbers in a Fibonancci sequence in an array9 Answersdef fibRecr(n): if n==1 or n==2: return 1 return fibRecr(n-1)+fibRecr(n-2) # Eg, to 15, store the sequence in array f1 for i in range (1, 15): f1.append(fibR(i))I think the key here is to use memoization so that you don't do have to calculate same value again as again in intermediate steps. Eg. in above solution, if we say find all values till 10, you have to calculate fibR(5) for 6, 7, 8, 9, 10 and since its recursive call this will not finish for even small size of n. Here is a solution using DP/memoization #define n 10 map m; //caches the intermediate steps int fib(int x) { auto it = m.find(x); if(it!= m.end()) return it->second; if(x == 0) { m = 0; return 0; } if(x == 1) { m = 1; return 1; } int val = fib(x-1) + fib(x-2); m[x] = val; return val; } int main (int argc, char *argv[]) { int result[n+1]; m[n] = fib(n); for(map::iterator it2= m.begin(); it2!= m.end(); it2++) // just to convert answer in an array form as asked result[it2->first] = it2->second; return 0; }I would write only the function and I assume that you will have to return the array: It goes as follows: long[] fib(int n){ long[] result= new long[n]; result=0; result=1; if(n<2) return result; for(int i=0;iShow More ResponsesI think this could be the answer (using iteration) void saveFib(int n){ int[] result = new int[n]; int a = 0, b=1 ,c =0; result=a; result=b for(int i=2;iisnt the question about returning an array? you dont need memoization // js let fibonacci = ((n) => { let arr = ; if(n > 0) arr = 1; if(n > 1){ let index = 2; while(index < n){ arr[index] = arr[index-1] + arr[index-2]; index++; } } return arr; }); console.log(fibonacci(5));``` import java.util.ArrayList; public class Fib { private int maxKnown = 2; private ArrayList arr = new ArrayList(); Fib() { arr.add(0); arr.add(1); arr.add(1); } public int calculate(int n) { if (n <= maxKnown) { return arr.get(n); } for (int i = maxKnown + 1; i <= n; i++) { arr.add(arr.get(i - 1) + arr.get(i - 2)); } return arr.get(n); } public static void main(String[] args) { Fib fib = new Fib(); System.out.println(fib.calculate(10)); System.out.println(fib.arr); } } ``` One or more comments have been removed. Please see our Community Guidelines or Terms of Service for more information.

Mar 21, 2017
 You are to write pseudo code O(n) algorithm to maximize a one day trade. You will have 5 days of predicted prices and your algorithm must choose what day to buy and sell to maximize gains. 6 AnswersThe brute force solution O(n^2) is simple... find the all of the permutation deltas and pick the largest value. You can trim some iteration by removing the permutation that are irrelevant such as buy and selling on the same day, or selling on the previous days, etc.... I thought about using the delta and track the rise and falls... However 25 minutes goes by pretty fast so I did not put any pseudo code on the test.. In hind site I should have put down the O(n^2) solutions to show I understood the problem and probably studiedHi, As a part of your interview process, were you asked to build any app ?I think this could be the answer you might be searching for. !! int maxP(int[] a){ if(a.length == 0) return 0; int max= a-a; int element = a; for(int i=1;imax){ max= a[i]-ele; } if(a[i]Show More Responsesdef max_profit(stocks): max_profit =0 min_stock = stocks max_stock = stocks for stock in stocks: min_stock = min(stock,min_stock) max_stock = max(max_stock,stock) max_profit = (max_stock - min_stock) return (max_profit) One or more comments have been removed. Please see our Community Guidelines or Terms of Service for more information.

Sep 17, 2019
 What is the fastest Big O equation? 4 Answers1.O=n, correct answer was log(n)1 < logn < n < nlogn < n^2 < 2n. Fastest is O(1) and slowest is O(2n)Not sure why but glassdoor replaced my less than operator with <. Replace < with less than operator for the above answerShow More ResponsesI think that should be O(1).

### Solutions Engineer at Deqode was asked...

Sep 19, 2019
 Given a 3-digit number, find the next number using the same digits. Eg. if number is 124, code must return 214.5 AnswersHello Folks, ``` #include using namespace std; typedef long long ll; typedef long double ld; #define MOD 1000000007 int main() { int t; cin>>t; while(t--) { int n; cin>>n; vector arr(n); for(int i=0; i> arr[i]; int idx = -1; for(int i=n-1; i > 0; i--){ if(arr[i-1] =0; i--) cout =idx+1; end--) { if(arr[idx] < arr[end]) break; } swap(arr[idx], arr[end]); sort(arr.begin() + idx +1 , arr.end()); for(int i=0; ifrom itertools import permutations n=int(input()) re=[] k=list(str(n)) p=list(permutations(k,len(k))) for i in range(len(p)): o="".join(p[i]) re.append(int(o)) re.sort() for i in range(len(re)): if re[i]==n: print(re[i+1])Show More ResponsesEdit : it's 142but the next number of 124 is 142. How it is 214? One or more comments have been removed. Please see our Community Guidelines or Terms of Service for more information.

Jul 11, 2017
 Balance parenthesis by removal, generate fibonacci. 5 AnswersRemove extra parenthesis with O(N) space and time complexity. Give a good solution to fibonacci that isn't the super complicated one that would take 45 minutes to draft.Fibonacci in O(n) time O(1) space: public int fibonacci(int n) { if (n == 1) return 1 int prev = 0, cur = 1; for(int i = 2; i <= n; i++} { int tmp = prev; prev = cur; cur = prev + cur; } return cur; }Show More ResponsesBalance Parenthesis public static String balanceParenthesis(String s) { StringBuilder str = new StringBuilder(s); int left = 0; for(int i = 0; i 0) { left--; } else { str.deleteCharAt(i--); } } } int right = 0; for(int i = str.length() - 1; i >= 0; i--) { if(str.charAt(i) == ')') { right++; } else if(str.charAt(i) == '('){ if(right > 0) right--; else { str.deleteCharAt(i); } } } return str.toString(); }Hi can you specify some question that we asked during the on site interview ? What was asked to code in the demo? One or more comments have been removed. Please see our Community Guidelines or Terms of Service for more information.

### Solutions Engineer at Intapp was asked...

Jun 15, 2011
 You have two balls on different tracks, traveling without friction. Ball A is on a straight track traveling from left to right, from point a to point b. Ball B is on a track with a dip, traveling from left to right, also from point a to point b (same horizontal distance). Which ball arrives at point b first (or fastest)?4 AnswersRemember there is no friction, and the track doesn't necessarily maintain a constant speed."I would assume both balls are at the same speed. Which means Ball A would arrive first because: 1) a straight line is shorter than curve 2) gravity will act on the ball B on the up curve"Don't they arrive at the same time? Since there's no friction, isn't the acceleration and deceleration in the z coordinate independent of the constant speed in the horizontal coordinate?Show More ResponsesThe answer is (b); the ball on the dipped track gets to the end first and wins the race. The two balls go along together for the first part of the race. As the ball on the dipped track goes down, its horizontal velocity increases, so it gets ahead. When it returns to its original level, it slows down to its original horizontal speed, but in so doing it never goes slower than the ball on the flat track, so it never gets behind the other ball or even allows the flat track ball to catch up. The two balls then move along at the same speed with the dipped track ball remaining ahead of the straight track ball by a constant amount.