Uber Interview Question for Software Engineers


Country: United States




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

This could be solved using minimum spanning tree concept

***assume taxi is large enough for all passengers****

Arrange all the pickup locations as vertices of a graph along with the present location of the taxi as

one of the vertex

now start with the present location and add that edge with has lowest weight ,this means we have

visited to the location which is nearby and pic all the passangers, then search for the next nearby location

locations and so on until all the locations are visited once

- Harsh Bhardwaj February 17, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I should add this to the problem: driver just pick up one person for each location.

- sonya.abdoli February 17, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Isn't it traveling salesman problem?

- afroza.sultana.kakon March 13, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

hmm... do you mean all permutations like
person1 - person6 - person 10 - person 13
person1 - person7 - person 10 - person 13
person1 - person8 - 10 - 13
1 - 9 - 10 - 13
1 - 6 - 11 - 13
etc...

- Chris March 13, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If the question is to get all permutations then this should do the trick:

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by dirkhain on 4/10/17.
 */
public class UberPickup {

    public static void main (String[] args) {
        UberPickup u = new UberPickup();
        List<String[]> input = new ArrayList<>();
        input.add(new String[]{"P1", "P2", "P3"});
        input.add(new String[]{"P4", "P5", "P6"});
        input.add(new String[]{"P7", "P8"});
        List<String> result = u.getPermutations(input);
        for (String s : result) {
            System.out.println(s);
        }
    }

    public List<String> getPermutations(List<String[]> input) {
        ArrayList<String> result = new ArrayList<>();
        if(input.size() == 0) {
            return Arrays.asList("");
        }
        String[] current = input.get(0);
        //copy rest of array
        List<String[]> rest = input.subList(1, input.size());
        List<String> subCombos = getPermutations(rest);
        for(String s : current) {
            for(int i = 0; i < subCombos.size(); i++) {
                String combo = subCombos.get(i);
                result.add("->" + s + combo);
            }
        }
        return result;
    }
}

If the question is not about retrieving the permutations then this solution will not work.

- dhc April 10, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{{ # Below is a rough implementation in python

locations = [
"p1,p2,p3,p4,p5",
"p6,p7,p8,p9",
"p10,p11,p12",
"p13,p14,p15"
]


def getSchedules(locations, capacity):

# format locations to some thing usable
locations = [ location.split(',') for location in locations ]

current_index = 0
result = []

def visitPeople(current_index):

allEmpty = True
for person in locations:
if current_index < len(person) and len(result) < capacity:
allEmpty = False
result.append(person[current_index])

if len(result) < capacity and not allEmpty:
visitPeople(current_index + 1)

visitPeople(current_index)

print(result)

# U can invoke the above function like so.
getSchedules(locations, 16) }}

- A Python implementation June 27, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

# Below is a rough implementation in python

locations = [
    "p1,p2,p3,p4,p5",
    "p6,p7,p8,p9",
    "p10,p11,p12",
    "p13,p14,p15"
]


def getSchedules(locations, capacity):

    # format locations to some thing usable
    locations = [ location.split(',') for location in locations ]

    current_index = 0
    result = []

    def visitPeople(current_index):

        allEmpty = True
        for person in locations:
            if current_index < len(person) and len(result) < capacity:
                allEmpty = False
                result.append(person[current_index])

        if len(result) < capacity and not allEmpty:
            visitPeople(current_index + 1)

    visitPeople(current_index)

    print(result)

# U can invoke the above function like so.
getSchedules(locations, 16)

- A Python implementation June 27, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

def combo(words,prefix=" "):
    if not words :
       print prefix
       return
    for i in words[0]:
        combo(words[1:],prefix+" "+i)
combo(locations)

- temp July 05, 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