careercupuser
BAN USER- 1of 3 votes
AnswersGiven
{ //"Restaurant Types"."[categoryNames]" "American" : "[Burger, French fries, Potato Chips]", "Italian":"[Pizza,Bread Sticks, Potato Chips]" }
Assume this kind of data is given as input and loaded into your choice of Data Structure.
- careercupuser in United States for Back-End Developer
Using Category name return the no of resturarnt type. Ex: if i/p is Potato Chips, O/P should be : 2 (American and Italian).
Please mention your Data structure and logic.| Report Duplicate | Flag | PURGE
Yelp Software Engineer / Developer Algorithm - 4of 10 votes
AnswersA man goes to a hardware shop and asks for price of an item. The shop keeper replies that the item is "one for $1".
- careercupuser in United States
The man gives the shop keeper "$3 for 600". What did the man buy for his newly painted house?| Report Duplicate | Flag | PURGE
Epic Systems Software Engineer / Developer Brain Teasers
public static boolean permute(ArrayList<Integer> prefix, ArrayList<Integer> input){
int sum1 = sum(prefix);
int sum2 = sum(input);
if(sum1 == sum2){
System.out.println("Sum: "+sum1);
return true;
}
else{
for(int i=0;i<input.size();i++){
//remove the element from input to prefix
prefix.add(input.remove(i));
boolean value = permute(prefix,input);
//add back the value from prefix to input
input.add(i, prefix.remove(prefix.size()-1));
if(value) return true;
}
}
return false;
}
private static int sum(List<Integer> arr) {
int sum =0;
for(Integer val : arr){
sum+=val;
}
return sum;
}
Can you explain your code?
- careercupuser January 09, 2016Only one plus operator should be used.
- careercupuser January 07, 2016You are adding numbers and storing them in a suffixes array? How do you handle Integer overflow cases?
All the number might be less than +Int.Max_Val but the sum might exceed max int value right?
O(n) time and O(1) space
public static int Manipulate(int[] a)
{
if (a.Length < 1)
return 0;
int i = -1, m = 0;
while (m < a.Length)
{
if (a[m] != 0)
{
i += 1;
a[i] = a[m];
}
m++;
}
int count = i + 1;
while (i+1 < m)
{
i += 1;
a[i] = 0;
}
return count;
}
public static boolean changed = true;
public static void main(String[] args) {
//System.out.println(remove("ABCCBCBA"));
String str = "AA";
//String str = "ABCCBCBA";
while(changed) {
changed = false;
str = remove(str);
if(str.length() < 1) {
str= "-1";
break;
}
}
System.out.println(str);
}
public static String remove(String s) {
StringBuilder str = new StringBuilder();
for(int i =0 ; i < s.length(); i++) {
if(i+1 < s.length() && s.charAt(i) == s.charAt(i+1)) {
changed = true;
while(i+1 < s.length() && s.charAt(i) == s.charAt(i+1))
i++;
}
else
str.append(s.charAt(i));
}
return str.toString();
}
Add this line to the else part of the if(day == 1) to make it work for the inputs with 2 3 2001 3 :
else {
month--;
day = numberOfDaysInMonthAndYear(month, year);
}
Repchandlernardone, Environmental engineering technician at Gamble-Skogmo
My journey began with a solid educational foundation, earning a degree in Environmental Engineering Technology. One of my favourite hobbies ...
Based on the sliding window concept, a O(N) solution.
1. Maintain two pointers
2. When SUM is equal to given N, then print the range and increment both the pointers.
- careercupuser February 09, 2016