AlgoBaba
BAN USER
- 0of 0 votes
AnswersDesign a system to find top 10 twitter hashtags in the most recent 1 min, 10 min, 1 hr
- AlgoBaba in United States| Report Duplicate | Flag | PURGE
Twitter Data Engineer Software Design - -1of 1 vote
AnswersFind K which decides the number of open brackets are equal to the number of closed brackets.
- AlgoBaba 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 | PURGE
Amazon SDE-2 Algorithm - 0of 0 votes
AnswersFind the Maximum number of distinct nodes in a binary tree path
- AlgoBaba in United States| Report Duplicate | Flag | PURGE
Amazon SDE-2 Algorithm - 4of 4 votes
AnswersReturn the length of longest possible chunked palindrome string.
- AlgoBaba 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 | PURGE
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.
- AlgoBaba in United States| Report Duplicate | Flag | PURGE
Adobe Computer Scientist Algorithm - 0of 0 votes
AnswerFind the possible (x,y) coordinates in a given 2-D chess board which are safe from the attack of a queen.
- AlgoBaba in United States| Report Duplicate | Flag | PURGE
Adobe Computer Scientist 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.
- AlgoBaba in India| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 0of 0 votes
AnswersDesign Twitter.
- AlgoBaba in United States| Report Duplicate | Flag | PURGE
Twitter Software Engineer design - 2of 2 votes
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 ?
- AlgoBaba in United States
(Use Dynamic Programming)| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Dynamic Programming - 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
- AlgoBaba 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 | PURGE
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 ?
- AlgoBaba in India| Report Duplicate | Flag | PURGE
Flipkart SDE1 Algorithm
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));
}
}
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));
}
}
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);
}
}
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')))
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
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 ??
- AlgoBaba June 25, 2013
Love the simplicity of this answer ! If anyone is wondering what's the complexity , then it's O(logn) [ base 3 , not base 2 ] .
- AlgoBaba November 25, 2014