Shock
BAN USER 2of 2 votes
AnswersIn a game, you bet using the following strategy. Whenever you lose a bet, you double the value of the bet for the next round. Whenever you win, the bet for the next round will be one dollar. You start the round by betting one dollar.
 Shock in India for Sustainability Engineering
For example, if you start with 20 dollars, and you win the bet in the first round, lose the bet in the next two rounds and then win the bet in the fourth round, you will end up with 20+112+4 = 22 dollars.
You are expected to complete the function, getFinalAmount, which takes two arguments. The first argument is an integer initialAmount which is the initial money we amount we have when we start the betting. The second argument is a string betResultsThe ith character of outcome will be either 'W' (win) or 'L' (lose), denoting the result of the ith round.
Your function should return the amount of money you will have after all the rounds are played. If at some point you don't have enough money in your account to cover the value of the bet, you must stop and return the sum you have at that point.
Sample Test Cases:
Input #00:
12
WWWWWWWW
Output #00:
20
Explanation:
The initial amount is 12, for every win, you gain 1 dollar.
There are totally 8 consecutive wins and no losses, hence total money gained = 12 + 8 = 20
Input #01:
15
LLLWLLLL
Output #01:
1
Explanation:
The initial amount is 15. As stated in the problem, the amount of bet doubles for every loss.
1st round  Loss: 151 = 14
2nd round  Loss: 142 = 12 (Bet doubles)
3rd round  Loss: 124 = 8
4th round  Win: 8 + 8 = 16
5th round  Loss:161 = 15 (Since the previous bet was a win, this bet has a value of 1 dollar)
6th round  Loss: 152 = 13
7th round  Loss: 134 = 9
8th round  Loss: 98 = 1 Report Duplicate  Flag  PURGE
McAfee Software Engineer / Developer Algorithm  0of 0 votes
AnswersComplete the function getEqualSumSubstring, which takes a single argument. The single argument is a string s, which contains only nonzero digits.
 Shock in India for Sustainability Engineering
This function should print the length of longest contiguous substring of s, such that the length of the substring is 2*N digits (maximum length of the string is 49) and the sum of the leftmost N digits is equal to the sum of the rightmost N digits.If there is no such string, your function should print 0.
Sample Test Cases:
Input #00:
123231
Output #00:
6
Explanation:
1 + 2 + 3 = 2 + 3 + 1.
The length of the longest substring = 6 where the sum of 1st half = 2nd half
Input #01:
986561517416921217551395112859219257312
Output #01:
36 Report Duplicate  Flag  PURGE
McAfee Software Engineer / Developer Algorithm  0of 0 votes
AnswersWrite implementation of PIVOT keyword found in SQL server.
 Shock in India Report Duplicate  Flag  PURGE
Intuit Software Engineer / Developer SQL
using System.Collections.Generic;
public class FastMinStack<T>
{
private readonly Stack<T> stack = new Stack<T>();
// Could pass this in to the constructor
private readonly IComparer<T> comparer = Comparer<T>.Default;
private T currentMin;
public T Minimum
{
get { return currentMin; }
}
public void Push(T element)
{
if (stack.Count == 0 
comparer.Compare(element, currentMin) <= 0)
{
stack.Push(currentMin);
stack.Push(element);
currentMin = element;
}
else
{
stack.Push(element);
}
}
public T Pop()
{
T ret = stack.Pop();
if (comparer.Compare(ret, currentMin) == 0)
{
currentMin = stack.Pop();
}
return ret;
}
}

Shock
March 22, 2013 Though the aim of interviewee seems to encourage the candidate to ask more questions about the arrangement of the trees in the forest and other requirements.
Given the problem here there seems to be only one solution >
Start with the leftmost (if the trees are linear) or any (if the trees are in circle) tree. Shoot one tree twice. If monkey is jumping to the left adjacent tree, it will be dead in the second shot. Otherwise if the monkey jumps to the right adjacent tree every time, it will be dead after sometime later. Even if the tree formation is circular, monkey will be dead.
Open Chat in New Window
no scenarios. Interviewer just wanted to store it. But it is easy to assume that once it is stored it is definitely going to be queried.
 Shock March 29, 2013