Yelp Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

Min Coin Problem

- Nitin Gupta July 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

First sort the array then pass the array, array length and total value to function

bool isTot(int arr[],int len,int tot) {
    bool sum[tot+1];
    sum[0] = true;
    
    for (int i=1;i < =tot;i++) {
        if (sum[i] < arr[0]) {
            sum [i] = false;
            continue;
        }
        sum[i] = false;
        for (int j = 0; j < len; j++) {
            if ((i-arr[j]) > 0) {
                if (sum[i-arr[j]]==true) {
                    sum[i] = true;
                    break;
                } 
            }
        }
    }
    return sum[tot];
}

- iwanna November 16, 2014 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

dp[0] = 1;
 for (int i=0; i < N; i++)
    for(j = a[i]; j <= W; j++)
           dp[j] |= dp[j-a[i]];
 return dp[W];

- Anonymous July 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

public static boolean isScorePossible(int[] points, int value){
		int status [] =new int [value+1];
		status [0]=1;
		for (int i=0;i<points.length;++i){
			for (int j=points[i];j<=value;++j){
				status[j]+=status[j-points[i]];
			}
		}
		
		return status[value]>0;

}

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

bool isScorePossible(int[] points, int finalScore)
{
  Map<Integer,Integer> myMap = new HasMap<Integer, Integer>();
  
  for(int i=0;i<points.length();i++) {
     myMap.put(points[i],points[i]);
  }

for(int i=0;i<points.length(); i++) {

if(points[i]<=finalScore) {
  int hold = Math.abs(points[i] - finalScore);
  if(myMap.containsKey(hold)){
  return true;
  }
  else {
  while ((points[i] + points[i])<finalScore){
  int hold = (points[i] + points[i];
  if(myMap.containsKey(hold) || hold==finalScore){
  return true;
  } 
  }
}
}
else
return false;
}
}

- struggler July 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

bool subsetSum(vector<int> &candidates, int sum) {
    sort(candidates.begin(), candidates.end());
    vector<bool> dp(candidates.size()+1, false);
    
    dp[0] = true;
    
    for (int i = 1; i <= sum; ++i) {
        for (int j = 0; j < candidates.size(); ++j) {
            if (candidates[j] <= i) {
                dp[i] = dp[i] | dp[i-candidates[j]];
                if (dp[i]) break;
            } else {
                break;
            }
        }
    }
    
    return dp[sum];
};

- yuanbing July 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/**
	 * N - array length
	 * M - value to check
	 * 
	 * time: O(N*M)
	 * space: O(lg M)
	 */
	boolean isScorePossible(int value, int[] arr){
		
		Arrays.sort(arr);
		
		BitSet sol = new BitSet(value+1);
		sol.set(0);
		
		for( int i = arr[0]; i < value+1; i++ ){
			
			for( int j = 0; j < arr.length; j++ ){
				if( arr[j] > i ){
					break;
				}
				
				if( sol.get(i-arr[j]) ){
					sol.set(i);
					break;
				}
			}			
		}
		
		return sol.get(value);
	}

- m@}{ July 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

boolean SubSetSum(int[] S, int target){
	// I assume that all the integers in S and the target is positive
	boolean[] A = new int[target];
	for(int i = 0; i<target; i++){
		int value = false;
		for(int j = 0; j<S.length; j++){
			if(S[j] == i+1){
				value = true;
				break;
			}
			else if(i+1 - S[j]> 0 && A[i+1-S[j]]){
				value = true;
				break;
			}
		}
		A[i] = value;
	}
	return A[target-1];
}

- ShiguangWang November 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def isScorePossible(points, result):
if(result in points):
return True
if(result<0):
return False
else:
flag = False
for point in points:
if(isScorePossible(points, (result-point)) or flag):
return True
return False

- weiqi November 12, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Is this just a backtracing problem?

def is_score_possible(n, points):
    if n in points:
        return True
    sub_points = [point for point in points if point < n]
    for pt in sub_points:
        if is_score_possible(n-pt, sub_points):
            return True
    return False



points = [3, 7]
print is_score_possible(10, points)
print is_score_possible(9, points)
print is_score_possible(8, points)
print is_score_possible(11,points)

- jason November 25, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def gcd(lst):
"""
>>> gcd([14,24,6,8])
2
>>> gcd((6,8,9,12,14))
1
>>> gcd([6, 9, 18, 36])
3
"""
non_zeroes = []
for elem in lst:
if elem != 0:
non_zeroes.append(elem)
assert len(non_zeroes) >= 1, "Error! Must have at least 1 non-zero item in the list!"
if len(non_zeroes) == 1:
return non_zeroes[0]
m = min(non_zeroes)
m_index = non_zeroes.index(m)
for i in range(len(non_zeroes)):
if i != m_index:
non_zeroes[i] %= m
return gcd(non_zeroes)

def is_score_possible(pts, score):
"""
>>> is_score_possible((3, 7), 10)
True
>>> is_score_possible((3, 7), 9)
True
"""
return score % gcd(pts) == 0

- Paul February 23, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def gcd(lst):
    """
    >>> gcd([14,24,6,8])
    2
    >>> gcd((6,8,9,12,14))
    1
    >>> gcd([6, 9, 18, 36])
    3
    """
    non_zeroes = []
    for elem in lst:
        if elem != 0:
            non_zeroes.append(elem)
    assert len(non_zeroes) >= 1, "Error! Must have at least 1 non-zero item in the list!"
    if len(non_zeroes) == 1:
        return non_zeroes[0]
    m = min(non_zeroes)
    m_index = non_zeroes.index(m)
    for i in range(len(non_zeroes)):
        if i != m_index:
            non_zeroes[i] %= m
    return gcd(non_zeroes)

def is_score_possible(pts, score):
    """
    >>> is_score_possible((3, 7), 10)
    True
    >>> is_score_possible((3, 7), 9)
    True
    """
    return score % gcd(pts) == 0

- Paul February 23, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Mod the score by each point (sorted by descending value). If 0, then we constructed the score by some product of the points. Otherwise it's impossible.

def isScorePossible(points, score):
for point in sorted(points, reverse=True):
score %= point
return score == 0

- Coltin March 20, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Mod the score by each point (sorted by descending value). If 0, then we constructed the score by some product of the points. Otherwise it's impossible.

def isScorePossible(points, score):
    for point in sorted(points, reverse=True):
        score %= point
    return score == 0

- Coltin March 20, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int rem = score;
Arrays.sort(points);
Arrays.sort(points, Collections.reverseOrder());
for(int a : points) {
if(score % a == 0 || rem % a == 0) {
return true;
} else {
rem = rem % a;
}
}
return false;

- Anonymous September 20, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def isScorePossible(points, value):
for i in points:
mod = value % i
if mod in points or mod == 0:
return True

- dev September 30, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def isScorePossible(points, value):
for i in points:
mod = value % i
if mod in points or mod == 0:
return True

- dev September 30, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def isScorePossible(points, value):
for i in points:
mod = value % i
if mod in points or mod == 0:
return True

- dev September 30, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def isScorePossible(points, value):
for i in points:
mod = value % i
if mod in points or mod == 0:
return True

- dev September 30, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def isScorePossible(points, value):
	for i in points:
		mod = value % i
		if mod in points or mod == 0:
			return True

- Anonymous September 30, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

static boolean recurse(int value){
		if (value == 0) return true;
		else if(value > 0)
			return (recurse(value-3) || recurse(value-7));
		else return false;
	}

- joganiparin October 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

First of all you dont get int value as argument, you will get array of integers.
And that value need not be 10 hence
return (recurse(value-3) || recurse(value-7));
is incorrect.
You need to write a generic program.

- struggler October 07, 2013 | Flag


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