Shortest Distance After Road Addition Queries I | Leetcode 3243

Поділитися
Вставка
  • Опубліковано 7 січ 2025

КОМЕНТАРІ • 15

  • @alessandrocamilleri1239
    @alessandrocamilleri1239 Місяць тому

    Thank you for the explanation. As a small optimisation you can also return early if one of the queries results in a shortest path of 1. In that case res would have to be initialised with size q and value 1 on declaration.

  • @sailendrachettri8521
    @sailendrachettri8521 Місяць тому

    Thank you sir :)

  • @21flame72
    @21flame72 Місяць тому

    Thankyou sir

  • @wallwall3140
    @wallwall3140 Місяць тому

    I’m big fan of ur work but this time I think there is a tips to do it more simply perhaps with indexes who can give you the direct distances… I need to dive in

  • @androidterminal3924
    @androidterminal3924 Місяць тому

    thanks

  • @taskeen_fatimaa
    @taskeen_fatimaa Місяць тому

    thankyou sir i want to build solid logic like you any suggestions pls do give

    • @techdose4u
      @techdose4u  Місяць тому +1

      Practice more and you'll build a strong logic over time.

  • @Rahul-wd2ux
    @Rahul-wd2ux Місяць тому

    getting time limit exceeded on normal bfs sir!! what optimisation can be done??

    • @techdose4u
      @techdose4u  Місяць тому

      I have also applied normal BFS. Can you please check once if your loop is breaking properly.

  • @avdhootgole2773
    @avdhootgole2773 Місяць тому

    I did it using adjacency matrix instead of list. Is that the reason why my solution takes a lot of runtime? (Ik Leetcode runtimes are not worth trusting, but assuming it would atleast be somewhat accurate)

    • @techdose4u
      @techdose4u  Місяць тому +1

      Matrix is good for dense graph while list is good for other sparser types. Since, most test cases are not dense hence your runtime must have been higher.