is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.
Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.
Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.
Lets assume the same example
- iprep.bc November 22, 2013A = ['a', 'b', 'c']
W = [0.3, 0.5, 0.2]
By probability, when randomChar( ) is called 10 times, a should appear 3 times, b should appear 5 times, c should appear 2 times.
Here 10 is a good number because it ensures every probability is turned into an integer corr. character is printed that many times. If we had an example like,
A = ['a', 'b', 'c']
W = [0.03, 0.5, 0.47]
we have to take 100 as the baseline since 0.03*100=3.
This method finds this ānā
int findN()
{
n=minElement(W);
while(n>0)
{
n=n*10;
}
return n;
}
// Create a copy of W in W1 and multiply all elements of W with this n.
void initializeWeights()
{
for(int i=0;i<W.length();i++)
{
W1[i]=W[i]*n;
}
}
This W1 is the number of times each character has to be printed if randChar( ) is called ānā times.
If the randChar( ) is run for n times, our code should ensure that every A[i] is print W[i] times *randomly*. Remember, it cant just print every element sequentially, then randChar() has no meaning! ;)
char randChar()
{
while(1)
{
p=rand(W1.length()); // printing a random number from 1 to W.length()
if(W1[p]>0) // this ensures that when a char at A[p] is printed for that many times it is supposed to
{
W1[p]--;
return A[p];
}
}
}
int main()
{
int j,n;
n=findN();
m=100; // number of times we are asked to print it
for(j=1;j<=10;j++)
{
initializeWeights() // assign back all the weights
for(k=1;k<=n;k++)
{
cout<<randChar( );
}
}
// set W back to its original numbers every n times
}
This is the first time I am posting answers in this forum. Please pardon syntactical mistakes!