Oracle Interview Question for Software Developers


Country: India




Comment hidden because of low score. Click to expand.
7
of 7 vote

Using bitwise OR:

public int rand75(){
	return rand50() | rand50();
}

- Roman July 23, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
3
of 3 vote

Generic pseudo-code, not intended to compile. Not tested, but I think it should work.

function int myRandom() {
    int roll1 = originalRandom();
    int roll2 = originalRandom();

    // Only 4 possible combinations, with equal probabilities:
    // roll1 = roll2 = 0
    // roll1 = roll2 = 1
    // roll1 = 0; roll2 = 1
    // roll1 = 1; roll2 = 0

    if (roll1 == 0 && roll2 == 0)  // 25% probability
        return 0;
    else  // 75% probability
        return 1;
}

- Anonymous July 23, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 vote

Considering rand50() is defined, then rand75() would be

char rand75() {
    return !(rand50() && rand50());
}

- nikolay.dimitrov July 23, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */

int rand50(){
    srand(time(NULL));
    int randInt= rand(); // randInt is between 0 and RAND_MAX
    (x%2)==0? return 1 : return 0;
}

int rand75(){
    int x = rand50();   // x is now one of {0, 1}
    x = x << 1;           // x is now one of {00, 10}
    x = x ^ rand50();  // x is now one of {00, 01, 10, 11} in binaries
    (x>0)? return 1 : return 0;
}

- jimmythefung July 22, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Pretty rusty with probabilities, so let me know your thoughts if this works out to be 75%
My first test, I rolled 12 times, got 9 rolls that returned 1, 3 rolls that return 0, gave me exactly: 9/12 = 75%
Sample size should be larger, so I should run more tests.

/* The lowest number of rolls to get a combination of 4 such that we can pick 3 out of 4
to give the 75% probability is through two rolls:

Roll Results
1: 0, 0
2: 0, 1
3: 1, 0
4: 1, 1

Pick 1 - 3 to return 1 for 75%
Pick 4 to return 0 for 25% probability
*/

#include <stdlib.h>
#include <time.h>
#include <iostream>

using namespace std;

int random50()
{
	int result = rand() % 2;
	return result;
}

int random75()
{
	const int size = 3;
	int valuesFor1[size] = { 0, 1, 10 };
	
	// First roll is for the 10's digit place
	int roll1 = random50();
	int roll2 = random50();
	int result = (roll1 * 10) + roll2;
	for (int i = 0; i < size; ++i) 
	{
		if (result == valuesFor1[i])
		{
			return 1;
		}
	}
	return 0;
}

int main() 
{
	srand (time(NULL));
	int value = random75();
	cout << value << endl;
	return 0;
}

- miharra July 22, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Generic pseudo-code, not intended to compile. Not tested, but I think it should work.

function int myRandom() {
    int roll1 = originalRandom();
    int roll2 = originalRandom();

    // Only 4 possible combinations, with equal probabilities:
    // roll1 = roll2 = 0
    // roll1 = roll2 = 1
    // roll1 = 0; roll2 = 1
    // roll1 = 1; roll2 = 0

    if (roll1 == 0 && roll2 == 0)  // 25% probability
        return 0;
    else  // 75% probability
        return 1;
}

- jgh July 23, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Generic pseudo-code, not intended to compile. Not tested, but I think it should work.

function int myRandom() {
    int roll1 = originalRandom();
    int roll2 = originalRandom();

    // Only 4 possible combinations, with equal probabilities:
    // roll1 = roll2 = 0
    // roll1 = roll2 = 1
    // roll1 = 0; roll2 = 1
    // roll1 = 1; roll2 = 0

    if (roll1 == 0 && roll2 == 0)  // 25% probability
        return 0;
    else  // 75% probability
        return 1;
}

- Juan July 23, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool rand75(){
if(rand50()==1)
return1;
return rand50();
}

- Anonymous July 23, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

from random import randint

# given function
def rand_50() :
    return randint(0,1)

# requested function
def rand_75() :
    if (rand_50() + rand_50()) == 2 :
        return 0
    else :
        return 1

# test distribution over n outcomes
def test(n) :
    outcome = 0
    for i in range(0,n) :
        outcome = outcome + rand_75()
    p_1 = outcome / n
    p_0 = 1 - p_1
    print("p_0= %s, p_1= %s " % (p_0, p_1))

test(10000)

- Luke Rhinehart July 23, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import random


def rand_0_5():
    return 1 if random.random() >= 0.5 else 0


def rand_0_75():
    return 0 if not (rand_0_5() + rand_0_5()) else 1

- frestuc July 23, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public int random75(){
	int ans = random50(); // 50%
	if(ans == 0){
		ans = random50();   //for 0 50% / 2 = 25%
	}
	return ans;
}

- satyen.shimpi January 09, 2017 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

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.

Learn More

Resume Review

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.

Learn More

Mock Interviews

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.

Learn More