Posts

Showing posts with the label Array&String questions

Pattern matching through regular expression [reviewed]

Problem Pattern Matching  ----------------  Characters: a to z  Operators: * +  * -> matches zero or more (of the character that occurs previous to this operator)  + -> matches one or more (of the character that occurs previous to this operator)  Output if a given pattern matches a string.  Example:  pattern:a*b  string:aaab b, ab, aab, aaab, ab  output:1  pattern:a+aabc  string:ab aabc, aaabc, aaaabc ..  output:0  pattern:aa*b*ab+  string:aab aab, aabab, aaaabbab  output:1  pattern: a+a*b*  string: a ab, aab, aaabb  output: 1  Valid Assumptions: Please assume that both the pattern and string input are valid

Given two strings, write a method to decide if one is a permutation of the other

Problem Given two strings, write a method to decide if one is a permutation of the other. Example)  Given two strings, "mom", "grandmom", your algorithm should return True because "mom" is the permutation of "grandmom".

Finding the minimum sub-string

Image
Problem Given the input string str1 and the seed string str 2, write the program to find the minimum sub-string of str1 that is inclusive of str 2. Example)  Case 1) str1 = "abbcbcba" and str2 = "abc", answer = "cba" Case 2) str1 = "caaababc" and str2 = "abc", answer = "abc"

Evaluating the mathmatic expression with parentheses

Image
Problem Given arithmetic equation, 2+(3-1)*4/(5-6), write the program to calculate the result of the equation.

Shuffling the deck of cards perfectly randomly.

Problem Write the program to shuffle the deck of cards in statistically random order.

Placing N queens in N x N Chess board

Image
Problem In $N \times N$  chess board, you have to arrange N queens such that they do not interfere each other. Following is how you define interference of queens.  1. Two queens cannot be on the same diagonal  2. Two queens cannot be in same horizontal or vertical line  3. Queen can jump like a knight. So, two queens cannot be at a position where they can jump two and half steps like a knight and reach the other queen.  You should return the possible ways to arrange N queens on a chess board. 

Moving zeros in the array to the left

Image
Problem  Push all the zero's of a given array to the end of the array. In place only. Ex 1 , 2 , 0 , 4 , 0 , 0 , 8 becomes 1 , 2 , 4 , 8 , 0 , 0 , 0. No additional allocation of array is not allowed. Everything should happen in place.

How to find a sequential sub array which has the biggest sum [reviewed]

Image
Problem Given a number array, including positive and negative numbers, the question is to find a sequential sub array which has the biggest sum and the time complexity is $O(n)$, For example, [1,-2,3,10,-4,7,2,-5] is an array, and the sub array [3, 10, -4, 7, 2] has the biggest sum which is 18.

Finding the sequential sub array totaling to the given number[reviewed]

Image
Problem Given an array of integer A = {23, 5, 4, 7,2, 11}, and the length N, and target sum, S, write the algorithm that tells whether the sub array $A_{sub}$, where $\sum_{i=k}^p A_{sub} (i) = S$. For example, If N = 3, and S = 13, it should return sub array, {4,7, 2}.

Look and Say sequence problem [reviewed]

Problem Implement the pattern function producing the following pattern:   0: 1   1: 11   2: 21   3: 1211   4: 111221   5: 312211  Your function should generate the  string sequences shown above, given the input as a integer.   For example, input = 4, output should be 111221

Finding the maximum drop in the stock price[reviewed]

Problem You are given the array of integers, each of which represents the stock price of each day. You need to find the maximum drop in the stock price and buying and selling date, such that input[x] > input[y], where  x > y  For example, given stock prices {2,4,-1,5, 7,6, 1}, the maximum drop should be 8, and [2, 4] will be an answer because the drop from -1 to 7 is 8, and the biggest increase. If the stock is bout when its price is at -1 and sells it when its price is at 7 the gain will be 8.