Day 1 in Bangalore

Day 1 in Bangalore

·

4 min read

👋
Hi, I'm Pranay Sinha, a 3rd year B.Tech student with a keen interest in the tech industry and a passion for learning.

I'm on a mission to master programming and tackle any coding challenge that comes my way. In this series, you'll find my daily journal entries, presented as simple bullet points. Nothing fancy—just my honest thoughts and experiences from each day. So, please, no judgment! 😂

Join me as I document my tech journey in Bangalore. Let's dive in!

Day 1 (30/06/2024)

  • Made a list of things I am going to focus on during my 2 months here, Mostly planning to revise my python fundamentals and learn some advanced concepts while also thinking about some simple personal projects

  • Tried to solve today's LeetCode problem 1579. Remove Max Number of Edges to Keep Graph Fully Traversable

  • Originally, I tried to come with a unique solution, but it turned out my approach was flawed from the start.. Only took me 2 hours to realize that..
    Anyway I saw the topics mentioned Disjoint sets, so I learnt about the Union & Find operations on Disjoint sets thanks to this guy and his blackboard. After that, it took me another hour to come with a solution and Implement it. I really need to practice more in order to reduce the time I take to implement these solutions.

    Nevertheless I was able to implement the solution in python, C++, and Go without much of a hassle. Just kidding—I had a typo in C++ where I didn't put the brackets in the if statement because in go you can't use brackets in your if statements

    Similarly, when writing the go code I put brackets around the conditionals of the for statement... I was staring at my screen for around 5 mins wondering what was wrong lol

    The fact that the error msg said unexpected := instead of warning me about the brackets really didn't help...

    So in short I am removing brackets from where they are needed and putting them in great hiding places 😂

  • Particularly proud of the Go implementation for some odd reason, idk it always feels nice to write some go code. Here's the implementation:

      type UnionFind struct {
          parent []int;
      }
    
      func NewUnionFind(n int) UnionFind{
          var uf UnionFind; 
          parent := make([]int, n+1)
          for i:=0;i<=n;i++ {
              parent[i] = i
          }
    
          uf.parent = parent
          return uf
      }
    
      func (uf UnionFind) find(i int) int{
          if i != uf.parent[i]{
              uf.parent[i] = uf.find(uf.parent[i]) 
          }
          return uf.parent[i]
      }
    
      func (uf UnionFind) union(i, j int) int{
          irep := uf.find(i)
          jrep := uf.find(j)
    
          if irep == jrep {
              return 0
          }
    
          uf.parent[irep] = jrep
          return 1
      }
    
      func (uf UnionFind) isConnected(n int) bool {
          p := uf.find(1)
          for i := 2; i<=n; i++{
              if p != uf.find(i){
                  return false
              }
          }
          return true
      }
    
      func maxNumEdgesToRemove(n int, edges [][]int) int {
          alice, bob := NewUnionFind(n), NewUnionFind(n)
    
          edgesRequired := 0
    
          for _, edge := range edges{
              if edge[0] == 3{
                  edgesRequired += (alice.union(edge[1], edge[2]) | bob.union(edge[1], edge[2]))
              }
          }
    
          for _, edge := range edges{
              if edge[0] == 2 {
                  edgesRequired += bob.union(edge[1], edge[2])
              } else {
                  edgesRequired += alice.union(edge[1], edge[2])
              }
          }
    
          if alice.isConnected(n) && bob.isConnected(n){
              return len(edges) - edgesRequired
          }
    
          return -1
      }
    
  • Solved a couple more Linked List and 2d Array related questions

  • Then I started to look into how python works under the hood watched a couple great videos, this one was the most helpful https://www.youtube.com/watch?v=tzYhv61piNY (Did you know Admiral Grace Hopper coined the term Compiler? I didn't)

  • Watched a few podcasts that had Guido Van Rossum in them

  • Decided I am going to start a tech journal So started looking at various options and settled for Hashnode (Great experience so far)

  • Wrote my first blog about all the things I learnt about the CPython Interpreter today. (Thinking that I should write a Blog every Sunday🤔)

Anyway that's about it for today! Today was really productive and informative. Excited for tomorrow! See you then!

Â