Max Level Sum Binary Tree"TITLE"Jump Game III Minesweeper" TITLE"Binary Tree Level Order"TITLE"Network Connections Operations"TITLE"Open Number Lock"TITLE"Sliding Puzzle Water Trapping"TITLE"Leetcode Notes Hitesh Mohapatra"TITLE"Network Component Algorithm"TITLE"Open Lock Algorithm Moves" TITLE"Sliding Puzzle Moves Solve
The document contains descriptions of several LeetCode problems ranging from Medium to Hard difficulty. It provides details about the Maximum Level Sum of a Binary Tree, Jump Game III, Minesweeper, Binary Tree Level Order Traversal, Number of Operations to Make Network Connected, Open the Lock, Sliding Puzzle, and Trapping Rain Water II problems. It also includes pseudocode and explanations for solving the Number of Operations to Make Network Connected and Open the Lock problems.
Similar to Max Level Sum Binary Tree"TITLE"Jump Game III Minesweeper" TITLE"Binary Tree Level Order"TITLE"Network Connections Operations"TITLE"Open Number Lock"TITLE"Sliding Puzzle Water Trapping"TITLE"Leetcode Notes Hitesh Mohapatra"TITLE"Network Component Algorithm"TITLE"Open Lock Algorithm Moves" TITLE"Sliding Puzzle Moves Solve
Similar to Max Level Sum Binary Tree"TITLE"Jump Game III Minesweeper" TITLE"Binary Tree Level Order"TITLE"Network Connections Operations"TITLE"Open Number Lock"TITLE"Sliding Puzzle Water Trapping"TITLE"Leetcode Notes Hitesh Mohapatra"TITLE"Network Component Algorithm"TITLE"Open Lock Algorithm Moves" TITLE"Sliding Puzzle Moves Solve (8)
Max Level Sum Binary Tree"TITLE"Jump Game III Minesweeper" TITLE"Binary Tree Level Order"TITLE"Network Connections Operations"TITLE"Open Number Lock"TITLE"Sliding Puzzle Water Trapping"TITLE"Leetcode Notes Hitesh Mohapatra"TITLE"Network Component Algorithm"TITLE"Open Lock Algorithm Moves" TITLE"Sliding Puzzle Moves Solve
1. Medium:
Maximum Level sum of a Binary Tree
Jump Game III
Minesweeper
Binary Tree Level Order Traversal
Number of operations to make network
connected
Open the lock
Hard:
Sliding Puzzle
Trapping Rain Water II
22-02-2021 Hitesh Mohapatra 1
Leetcode
14. 1319. Number of Operations to Make Network
Connected
• There are n computers numbered from 0 to n-1 connected
by Ethernet cables connections forming a network
where connections[i] = [a, b] represents a connection
between computers a and b. Any computer can reach any
other computer directly or indirectly through the network.
• Given an initial computer network connections. You can
extract certain cables between two directly connected
computers, and place them between any pair of
disconnected computers to make them directly connected.
Return the minimum number of times you need to do this
in order to make all the computers connected. If it's not
possible, return -1.
22-02-2021 Hitesh Mohapatra 14
18. Algorithm
• Make Adjacency List
• Find number of components by using DFS
• Find number of redundant edges
– When(Redundant edges >= component -1)
– Then (Edges required = (C-1)
Negative Case
• Edge < number of nodes -1
• Redundant edges < component-1
22-02-2021 Hitesh Mohapatra 18
19. 752. Open the Lock
• You have a lock in front of you with 4 circular wheels. Each
wheel has 10 slots: '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'. The
wheels can rotate freely and wrap around: for example we
can turn '9' to be '0', or '0' to be '9'. Each move consists of
turning one wheel one slot.
• The lock initially starts at '0000', a string representing the
state of the 4 wheels.
• You are given a list of deadends dead ends, meaning if the
lock displays any of these codes, the wheels of the lock will
stop turning and you will be unable to open it.
• Given a target representing the value of the wheels that
will unlock the lock, return the minimum total number of
turns required to open the lock, or -1 if it is impossible.
22-02-2021 Hitesh Mohapatra 19
23. Algorithm
• Initiate the with 0000
• Find out potential neighbors
• Check neighbor with deadends
• Take the turn where turn != deadends
• Count the number of turn to meet the target.
Negative Side
• If initial state is == deadend ; return -1
• If all the possible moves are falls under deadends
; return -1
22-02-2021 Hitesh Mohapatra 23
24. 773. Sliding Puzzle
• On a 2x3 board, there are 5 tiles represented by
the integers 1 through 5, and an empty square
represented by 0.
• A move consists of choosing 0 and a 4-
directionally adjacent number and swapping it.
• The state of the board is solved if and only if
the board is [[1,2,3],[4,5,0]].
• Given a puzzle board, return the least number of
moves required so that the state of the board is
solved. If it is impossible for the state of the
board to be solved, return -1.
22-02-2021 Hitesh Mohapatra 24