UBER SENIOR SOFTWARE ENGINEER

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2024-12-19Added By Anonymous
Source:Ā Link
🧭 Experience: unknown āœ… Outcome: unknown šŸ’° Compensation: unknown šŸ“ Location: unknown šŸ¢ Company: Uber šŸŽ“ Education: unknown šŸŽ Benefits: unknown šŸ“… Offer Date: unknown Interview question: - https://leetcode.com/problems/bus-routes/description/ modified version of above question problem statement:- need to find minimum bus change to reach to the destination from source. and every bus run in the infinite loop Ex:- [[1,5,7],[3,6,7],[9,8,7]] source = 1 , destination =8 ; output = 2; same bus like:- 1->5-7->1 running in a loop as two bus change via interconnected nodes Ex:- [[1,5,7],[3,6,7],[9,8,7]] source = 1 , destination =7 ; output = 0; as same loop is running so no bus chnage required 1->5->7->1 ``` import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Queue; /* * uber interview * There is a HCV * h1 = [1,5,7][3,6,7] * source = 1 ,dest = 6; * output=1 (because 1 route is changed from row 0 to row 1) * h1 = [[1,5,7],[3,5,6],[9,7,5]] * output = 2 ((because 1 route is changed from row 0 to row 1 and from row 1 to row 2) * source = 1 ,dest = 9; * */ public class BusRoute_2 { public HashMap<integer,list<integer>> adj ; public BusRoute_2(int mat[][]) { adj = new HashMap<>(); for(int i=0;i<mat.length;i++)> lp = adj.get(x); lp.add(i); adj.put(x,lp); }else { List<integer> lp = new ArrayList<integer>(); lp.add(i); adj.put(x,lp); } } } } public int minimumBusChange(int mat[][],int source,int dest) { boolean visitedRoutes[]=new boolean[mat.length]; if(source==dest) { return 0; }else if(!adj.containsKey(source)|| !adj.containsKey(dest)) { return 0; } else { Queue<integer> q = new LinkedList<integer>(); q.add(source); int count=0; while(!q.isEmpty()) { for(int i=0;i
Comments