Skip to content

Uber Coding Questions - DSA Problems & Solutions

Practice Uber placement paper coding questions with detailed solutions. Access Uber OA coding problems in Java, Python, JavaScript.

This page contains Uber coding questions from Uber OA placement papers with detailed solutions.

Uber OA Coding Section:

  • Problems: 2-3 coding problems
  • Time: 90 minutes
  • Languages: Java, Python, JavaScript
Q1: Find optimal route between two points considering traffic.

Solution (Java):

public List<Location> findOptimalRoute(Location start, Location end, Map<Location, List<Edge>> graph) {
// Use Dijkstra's algorithm with traffic weights
PriorityQueue<PathNode> pq = new PriorityQueue<>((a, b) ->
Double.compare(a.totalTime, b.totalTime));
Map<Location, Double> distances = new HashMap<>();
Map<Location, Location> previous = new HashMap<>();
pq.offer(new PathNode(start, 0.0));
distances.put(start, 0.0);
while (!pq.isEmpty()) {
PathNode current = pq.poll();
if (current.location.equals(end)) break;
for (Edge edge : graph.getOrDefault(current.location, new ArrayList<>())) {
double newTime = current.totalTime + edge.timeWithTraffic;
if (newTime < distances.getOrDefault(edge.to, Double.MAX_VALUE)) {
distances.put(edge.to, newTime);
previous.put(edge.to, current.location);
pq.offer(new PathNode(edge.to, newTime));
}
}
}
return reconstructPath(previous, start, end);
}

Time Complexity: O((V + E) log V)


Practice Uber coding questions regularly!