Daily Leetcode Challenge | DEC 22 | Find Building Where Alice and Bob Can Meet

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ม.ค. 2025

ความคิดเห็น • 5

  • @darshankumar5546
    @darshankumar5546  11 วันที่ผ่านมา

    //java
    import java.util.*;
    import java.lang.Math;
    class Solution {
    public int[] leftmostBuildingQueries(int[] heights, int[][] queries) {
    int q=queries.length;
    int n=heights.length;
    int[] ans=new int[q];
    Arrays.fill(ans,-1);
    List queryStore=new ArrayList(n);
    for(int i=0;ia.get(0)-b.get(0));
    for(int i=0;i

  • @antrasen77
    @antrasen77 9 วันที่ผ่านมา +1

    Thanku for the explanation

  • @darshankumar5546
    @darshankumar5546  11 วันที่ผ่านมา

    Please comment here, if you need Hindi Explanation of This Solution

  • @darshankumar5546
    @darshankumar5546  11 วันที่ผ่านมา

    #Python
    #TC=O(n+q+qlogq)=O(n+qlogq)=O(qlogq)
    #SC=O(n+q)
    import heapq
    class Solution:
    def leftmostBuildingQueries(self, heights: List[int], queries: List[List[int]]) -> List[int]:
    q=len(queries)
    n=len(heights)
    ans=[-1 for _ in range(q)] #O(q)
    queryStore=[[] for _ in range(n)] #O(n+q)
    minHeap=[] #O(q)
    for i in range(q): #O(q)
    a,b=min(queries[i]),max(queries[i])
    if(a==b or heights[b]>heights[a]):
    ans[i]=b
    else:
    queryStore[b].append((max(heights[b],heights[a]),i))
    print(ans)
    print(queryStore)


    for i in range(n): #O(n)
    while(minHeap and minHeap[0][0]