SmashDUNK
 1of 1 vote
AnswersFind K which decides the number of open brackets are equal to the number of closed brackets.
 SmashDUNK in United States
input : (())
output : 2
Reason : if we divide the string at 2nd position, we get two open brackets and two closing brackets, and they are same .
input : (())))(
output : 4
Reason : if we divide the string(not necessarily equally) at 4rth position, we have (()) on the left side and on the right side we have ))( , as you can see, on the left half, we have two opening brackets and on the right half we have two closing brackets and they are equal .
input : ))
output : 2
Reason : there is no open brackets , so if we divide taking the whole string's length, we have )) on the left half and nothing on the right half. Now you can see that on the left half there is no open brackets and on the right half there is no closed brackets.
This question should be clear by now and remember you have to find out that K . Report Duplicate  Flag
Amazon SDE2 Algorithm  0of 0 votes
AnswersFind the Maximum number of distinct nodes in a binary tree path
 SmashDUNK in United States Report Duplicate  Flag
Amazon SDE2 Algorithm  0of 0 votes
AnswersCheck if two given binary trees(expression trees with two characters 'a' and 'b' and obviously operators like +,,*) are mathematically equivalent?
 SmashDUNK in United States Report Duplicate  Flag
Google Software Engineer / Developer Algorithm  4of 4 votes
AnswersReturn the length of longest possible chunked palindrome string.
 SmashDUNK in United States
Examples :
Input : VOLVO
Output : 3
Explanation :
(VO)L(VO)
Input : merchant
Output : 1
Explanation : No chunks possible.
Input :
ghiabcdefhelloadamhelloabcdefghi
Output : 7
Explanation :
(ghi)(abcdef)(hello)(adam)(hello)(abcdef)(ghi) Report Duplicate  Flag
Google Software Engineer / Developer Algorithm  1of 1 vote
AnswersGiven a pattern and a string  find if the string follows the same pattern Eg: Pattern : [a b b a], String : cat dog dog cat
 SmashDUNK in United States Report Duplicate  Flag
Google Software Engineer / Developer Algorithm  0of 0 votes
AnswersFind out the number of ways in which two queens can be placed in a 8*8 chessboard.
 SmashDUNK in United States Report Duplicate  Flag
Adobe Computer Scientist Algorithm  0of 0 votes
AnswerFind the possible (x,y) coordinates in a given 2D chess board which are safe from the attack of a queen.
 SmashDUNK in United States Report Duplicate  Flag
Adobe Computer Scientist Algorithm  3of 3 votes
AnswersTom works in a warehouse. A billion (1,000,000,000) boxes are arranged in a row. They are numbered from one to one billion (from left to right). Some boxes contain a basketball (at most one basketball in each box). In total, there are N basketballs.Tom wants to organize the warehouse. He would like to see all the basketballs arranged next to each other (they should occupy a consistent interval of boxes). In one move, Tom can take one basketball and move it into an empty box. What is the minimum number of moves needed to organize the basketballs in the warehouse?
Write a function:class Solution { public int solution(int[] A); }
that, given an array A containing N integers, denotes the positions of the basketballs (the numbers of the boxes in which they are placed) and returns the minimum number of moves needed to organize the basketballs in the warehouse.
 SmashDUNK in United States
For example, given: A = [6, 4, 1, 7, 10], your function should return 2 because the minimum number of moves needed to arrange all basketballs next to each other is 2. There are several ways to do it. For example, you could move the ball from the first box to the fifth, and the ball from the tenth box to the eighth. You could also move the ball from the first box to the fifth, and the ball from the tenth box to the third instead. In any case, you need at least two moves.
To be done in O(nlogn) Time complexity and O(1) space complexity Report Duplicate  Flag
Google Software Engineer / Developer Algorithm  2of 2 votes
AnswersGiven a function getRandom that returns a random double in [0,1). Write a function getRandomPermutation(int n) that takes a positive integer n as argument and returns a random permutation of first n natural numbers.
 SmashDUNK in India Report Duplicate  Flag
Google Software Engineer / Developer Algorithm  0of 0 votes
AnswersDesign Twitter.
 SmashDUNK in United States Report Duplicate  Flag
Twitter Software Engineer design  1of 1 vote
AnswersYou have 81 balls. 80 balls have the same weight. 1 ball is the lightest one. What would be the minimum possible way to find the lightest ball ?
 SmashDUNK in United States
(Use Dynamic Programming) Report Duplicate  Flag
Amazon Software Engineer / Developer Dynamic Programming  0of 0 votes
AnswersFind the permutation of a given string using dynamic programming . Try to do with the best possible time complexity and space complexity .
 SmashDUNK in India Report Duplicate  Flag
Amazon Dev Lead Dev Lead Algorithm  0of 0 votes
AnswersAn array of size n is given. The array contains digits from 0 to 9. I had to generate the maximum number using the digits in the array such that it is divisible by 2, 3 and 5
 SmashDUNK in India
eg: 1 array = 18760, output must be: 8160
eg: 2 array = 7776, output must be: “no number can be formed” Report Duplicate  Flag
Amazon Algorithm  0of 0 votes
AnswersLet's say a website attracts a lot of traffic . How would you find at what instant of time (milliseconds or seconds , assume as you want) the traffic was super high ? What data structure would you go for and why ?
 SmashDUNK in India Report Duplicate  Flag
Flipkart SDE1 Algorithm  1of 1 vote
Answersyou have an array which has a set of positive and negative numbers, print all the subset sum which is equal to 0.
 SmashDUNK in United States
eg 2, 1, 1, 0, 2, 1, 1
o/p: 1, 1
1, 1, 0
0
2, 1, 1 Report Duplicate  Flag
Amazon Software Engineer / Developer
Use Recursion !!
public class RemoveStrings {
private static String removeStrings(String str) {
if(str.contains("ab")  str.contains("cd")) {
str = str.replace("ab", "");
str = str.replace("cd", "");
return removeStrings(str);
}
return str;
}
public static void main(String args[]) {
String s = "ccdaabcdbb";
System.out.println(removeStrings(s));
}
}

SmashDUNK
November 14, 2014 public class RemoveStrings {
private static String removeStrings(String str) {
if(str.contains("ab")  str.contains("cd")) {
str = str.replace("ab", "");
str = str.replace("cd", "");
return removeStrings(str);
}
return str;
}
public static void main(String args[]) {
String s = "ccdaabcdbb";
System.out.println(removeStrings(s));
}
}

SmashDUNK
November 14, 2014 import java.util.*;
public class Common
{
public static void func(int [] array1,int[] array2)
{
HashSet<Integer> al=new HashSet<Integer>();
HashSet<Integer> all=new HashSet<Integer>();
for (int i:array1)
{
al.add(i);
}
for (int j:array2)
{
all.add(j);
}
al.retainAll(all);
System.out.println(al);
}
public static void main(String args[])
{
int[] array1={1,2,3,4,3,2,1,2,3,4,5,6,4,3,2};
int[] array2={4,7,6,5,4,5,6,7,5,5,8,9,0};
func(array1,array2);
}
}

SmashDUNK
June 20, 2014 d = { '0': "zaqxsw",
'1': "cde",
'2': "vfr",
'3': "bgt",
}
def digstolets(digs):
if len(digs) == 0:
yield ''
return
first, rest = digs[0], digs[1:]
if first not in d:
for x in digstolets(rest): yield first + x
return
else:
for x in d[first]:
for y in digstolets(rest): yield x + y
print(list(digstolets('1230')))

SmashDUNK
October 12, 2013 Well here is a code written very easily in Python 3.3.2, have a look :)
def string():
a=input("Enter the string: ")
b=input("Enter the substring: ")
print("The strings are :",a,b)
if b in a:
print("After removing the substring: ",a.replace(b,''))
else:
return 1

SmashDUNK
September 29, 2013 there is a fault in the question if m nt wrong....this is obviously they asked things related to the compiler design/theory of computing related topics....or shud i say turing machine related things...but the problem is on what basis Google wants u to print those 1's or 00's ,cause ofcourse u need to generate 101 only once...but what about the first two elements...upto infinity ??
 SmashDUNK June 25, 2013Open Chat in New Window
Love the simplicity of this answer ! If anyone is wondering what's the complexity , then it's O(logn) [ base 3 , not base 2 ] .
 SmashDUNK November 25, 2014