10 Software Interview Questions
Real job-interview questions with full solutions. Filter, solve and prepare for your next interview.
You are given a list of stock prices for a given day, and your goal is to return the maximum profit that could have been made by buying a stock at the given price and then selling the stock later. For example, if the input is: [35, 11, 40, 35, 31, 28, 24, 45] then your program should return 34 because if you bought the stock for $11 and sold it for $45, you made a profit of $34, and that is the largest profit that can be made. If no profit could be made, return zero.
Input Output prices = [35, 11, 40, 35, 31, 28, 24, 45]buy at 11 and sell at 45.
34prices = [7, 1, 2, 5, 3, 6, 4]6 - 1 = 5.
5prices = [50, 40, 30, 20, 10, 5]the price only falls, so no profit is possible.
0It is known that an element in a sorted array can be found using O(log(n)) operations through binary search. Suppose we rotate the array around an unknown axis; for example, the array [1,2,3,4,5] becomes [3,4,5,1,2]. Devise a method to locate an element in the new array while maintaining the same time complexity.
Input Output nums = [3, 4, 5, 1, 2], target = 13nums = [15, 18, 2, 3, 6, 12, 14], target = 33nums = [4, 5, 6, 7, 0, 1, 2], target = 3-1Write a function that accepts a string, and prints all its possible permutations.
Input Output s = "abc"3! = 6 permutations, one per line. The order of the lines does not matter.
abc, acb, bac, bca, cab, cbas = "ab"ab, baGiven s and q strings. Return the index value of s if q is a substring of s, otherwise, return minus one.
Input Output s = "abcdefg", q = "de"3s = "chatgpt", q = "GPT"matching is case-sensitive.
-1s = "aaab", q = "aab"1Given an image with spots, it can be described as a matrix of 0's and 1's, so 1 is part of a spot. How will you find the number of spots?
Input Output grid = [[1, 0, 0, 1], [0, 1, 1, 0], [1, 1, 0, 0], [0, 0, 1, 1]]4grid = [[1, 0], [0, 1]]diagonal neighbors are not connected.
2grid = [[1, 1, 1], [1, 0, 1], [1, 1, 1]]1



