PCB
BAN USER- 0of 0 votes
AnswersShare market. Given an price of share in order of day as integer array, find out when an user can buy n when he/she can sell to gain maximum profit.
- PCB in United States
ex : 30, 12, 15, 10, 40, 30, 60, 100,
out put : 10 and 100
30, 12, 15, 10, 40, 30, 60, 100, 2, 110,
out put : 2, 110
30, 12, 15, 5, 40, 30, 60, 130, 2, 110
output: 5, 130| Report Duplicate | Flag | PURGE
Symantec Senior Software Development Engineer Algorithm - -1of 1 vote
AnswersValidating curly braces in java.
- PCB in India| Report Duplicate | Flag | PURGE
Symantec Senior Software Development Engineer Algorithm - 0of 0 votes
AnswersImplement a lift. They asked me to tell the logic.
- PCB in India| Report Duplicate | Flag | PURGE
Symantec Senior Software Development Engineer Algorithm - 0of 0 votes
AnswersReversing a character array.
- PCB in India
Steps:
1. Take two ref one will referring to start index n one to end index.
2. Swap characters at both indexes
3. Increment start index, decrement end index.
4. Repeat steps 2 and 3 untill u start index < end index
Complexity of this algorithm? IS there an algorithm using which we can achieve complexity of n/2?| Report Duplicate | Flag | PURGE
Symantec Senior Software Development Engineer Algorithm - 0of 0 votes
AnswersHow subString works in String class.
- PCB in India
subString will not create new string. Class string is having offset and count integers to point to begin index and number of characters.
subString will set these offset and count.| Report Duplicate | Flag | PURGE
Symantec Senior Software Development Engineer Java - 0of 0 votes
AnswersExplain equlas & hashcode methods. When you will override these two methods?
- PCB in India
This same question was asked in other two face to face interviews also. You should know how HashMap actually works. Like collision, put, get.
How to increase HashMap performance.| Report Duplicate | Flag | PURGE
Symantec Senior Software Development Engineer Java - 0of 0 votes
AnswersImplement Iterator for integer array.
- PCB in India| Report Duplicate | Flag | PURGE
Symantec Senior Software Development Engineer Algorithm - 0of 0 votes
AnswersAccording to the story, four prisoners are arrested for a crime, but the jail is full and the jailer has nowhere to put them. He eventually comes up with the solution of giving them a puzzle so if they succeed they can go free but if they fail they are executed.
- PCB in India
The jailer puts three of the men sitting in a line. The fourth man is put behind a screen (or in a separate room). He gives all four men party hats (as in diagram). The jailer explains that there are two red and two blue hats; that each prisoner is wearing one of the hats; and that each of the prisoners is only to see the hats in front of them but not on themselves or behind. The fourth man behind the screen can't see or be seen by any other prisoner. No communication between the prisoners is allowed.
If any prisoner can figure out and say to the jailer what colour hat he has on his head all four prisoners go free. If any prisoner suggests an incorrect answer, all four prisoners are executed. The puzzle is to find how the prisoners can escape, regardless of how the jailer distributes the hats?| Report Duplicate | Flag | PURGE
Goldman Sachs Developer Program Engineer Algorithm - 1of 1 vote
AnswersFind wether there is a loop in a given liked list or no?
- PCB in India
I solved it using two pointers. But they were not satisfied as I knew this solution before. They wanted me to solve using Single pointer.| Report Duplicate | Flag | PURGE
Goldman Sachs Developer Program Engineer Algorithm - 0of 0 votes
AnswersPrint 'n' elements of fibonacci series.
- PCB in Indiapublic int fibonacci(int n) { if ((n == 1) || (n==2)) { System.out.print("\t" + 1); return 1; } int temp = fibonacci (n-1) + fibonacci (n-2); System.out.println("\t" + temp); return temp;
| Report Duplicate | Flag | PURGE
Goldman Sachs Developer Program Engineer Algorithm
class StringReverse {
public static void main(String []args) {
System.out.println(revString("This is a test"));
}
static String revString(String str) {
System.out.println(str);
int length = str.length()-1;
if ( length ==0 )
return String.valueOf(str.charAt(0));
if ( length == 1 )
return String.valueOf(str.charAt(1)) + String.valueOf(str.charAt(0));
return String.valueOf(str.charAt(length)) + revString(str.substring(1, length)) + String.valueOf(str.charAt(0));
}
}
import java.util.Set;
import java.util.HashSet;
import java.util.Arrays;
class Palindrome {
public static void main(String args[]) {
String string = "A man, a plan, a canal: Panama.";
String str = string.toLowerCase();
int start = 0;
int end = str.length() - 1;
Set<Character> set = new HashSet<Character>(Arrays.asList('.', ';', ' ', ',', ':'));
while (start < end) {
char cStart = str.charAt(start);
char cEnd = str.charAt(end);
if (set.contains(cStart)) {
start++;
continue;
}
if (set.contains(cEnd)) {
end--;
continue;
}
if (cStart != cEnd)
break;
start++;
end--;
}
if (start < end)
System.out.println("String is not palindrom");
else
System.out.println("String is palindrom");
}
}
class MyString {
public static void main(String []args) {
String str = "ababcdef";
String subStr= "abc";
boolean flag = false;
if (str.length() < subStr.length())
System.out.println(subStr + " is not a sub string of " + str);
int i = 0
for ( ; i < str.length() -subStr.length() + 1; i++) {
int index = 0;
flag = true;
for ( int j = 0 ; j < subStr.length() ; j++) {
if (str.charAt(i+index) != subStr.charAt(j)) {
flag = false;
break;
}
index++;
}
if (flag) break;
}
if (flag) {
System.out.println(subStr + " is a sub string of " + str);
} else {
System.out.println(subStr + " is not a sub string of " + str + " @ index of " + i);
}
}
}
Hey satish. Everything is given in the problem. See the solution below.
- PCB August 12, 2013If in a line where A can see B & C. And B can see only C. D is away.
A -> B -> C
If A see red-red or blue-blue then he knows his is blue or red respectively. If A sees red-blue or blue-red keeps silent.
If A keeps silent then B knows the hat on his is different than than on C. So, if B sees red on C's head he know his is blue and vice versa.
All prisoners go free.