2026 April 11 Problems

23 views
Skip to first unread message

daryl...@gmail.com

unread,
Apr 11, 2026, 12:49:18 PM (9 days ago) Apr 11
to leetcode-meetup
Feel free to work on any of the problems you want; we'll have people present their solutions at 11:30.

Please post your solutions to this thread so others can use this as a reference.


3607. Power Grid Maintenance Medium 56.2%



We will have a different Zoom meeting that Bhupathi is providing this week:

Here is the meeting url:

Full details:

Topic: Leet Code meeting
Time: Mar 28, 2026 10:00 AM Pacific Time (US and Canada)
        Every week on Sat, 110 occurrence(s)
Please download and import the following iCalendar (.ics) files to your calendar system.
Weekly: https://us05web.zoom.us/meeting/tZYocuqgqzMuH9IuHUphHIiZ_4T4IndJLToX/ics?icsToken=DJFc88pL6-me_TneLwAALAAAAA70ShjYgLH6RfEnqUm5LK03v2OgtbXujwlKXRMVgIVWCY9aONPJMCycMlkhyPZ3XSrMVVgXDSYlGF_r7DAwMDAwMQ&meetingMasterEventId=MGJmt5lJTd6mPygcS0hiAQ
Join Zoom Meeting
https://us05web.zoom.us/j/82553858456?pwd=fnK5Vb0CcfFpv0lnouILjeEs2z2Khc.1

Meeting ID: 825 5385 8456
Passcode: 182596

Anuj Patnaik

unread,
Apr 11, 2026, 1:12:40 PM (9 days ago) Apr 11
to leetcode-meetup
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def inorderTraversal(self, root: Optional[TreeNode]) -> List[int]:
inorder_arr = []
stack = []
curr = root
while len(stack) > 0 or curr is not None:
while curr is not None:
stack.append(curr)
curr = curr.left
curr = stack.pop()
inorder_arr.append(curr.val)
curr = curr.right
return inorder_arr

Allen S.

unread,
Apr 11, 2026, 1:30:04 PM (9 days ago) Apr 11
to leetcode-meetup
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func inorderTraversal(root *TreeNode) []int {
res := []int{}
dfs(root, &res)
return res
}
//LNR
func dfs(root *TreeNode, vals *[]int) {
if root == nil {
return
}
dfs(root.Left, vals)
*vals = append(*vals, root.Val)
dfs(root.Right, vals)
}

Carlos Green

unread,
Apr 11, 2026, 2:07:14 PM (9 days ago) Apr 11
to leetcode-meetup
/**
* Definition for a binary tree node.
* function TreeNode(val, left, right) {
* this.val = (val===undefined ? 0 : val)
* this.left = (left===undefined ? null : left)
* this.right = (right===undefined ? null : right)
* }
*/
/**
* @param {TreeNode} root
* @return {number[]}

preorder: root, left, right
inorder: left, root, right
postorder: left, right, root

RECURSIVE SOLUTION

var inorderTraversal = function(root) {
const output = []

const inorder = (node) => {
if (!node) return
inorder(node.left)
output.push(node.val)
inorder(node.right)
}

inorder(root)
return output
}
*/

// ITERATIVE SOLUTION
var inorderTraversal = function(root) {
const stack = []
const output = []
let node = root

while(node !== null || stack.length !== 0) {
while(node !== null) {
stack.push(node)
node = node.left
}

node = stack.pop()
output.push(node.val)
node = node.right
}

return output
};

Allen S.

unread,
Apr 11, 2026, 5:44:23 PM (8 days ago) Apr 11
to leetcode-meetup
It's a long solution:
func processQueries(c int, connections [][]int, queries [][]int) []int {
isOnline := make([]bool, c + 1)
for i := range isOnline {
isOnline[i] = true
}

// build graph
g := make([][]int, c + 1)
for _, v := range connections {
g[v[0]] = append(g[v[0]], v[1])
g[v[1]] = append(g[v[1]], v[0])
}

// identify grids
station2grid := make(map[int]int)
grids := []*grid{}
visited := make([]bool, c + 1)
for stationID := 1; stationID <= c; stationID++ {
if !visited[stationID] {
stations := []int{}
gridID := len(grids)
dfs(stationID, gridID, &stations, visited, g, station2grid)
slices.Sort(stations)
newGrid := grid{stations, 0}
grids = append(grids, &newGrid)
}
}

// run queries
res := []int{}
for _, v := range queries {
if v[0] == 1 {
stationID := v[1]
if isOnline[stationID] {
res = append(res, stationID)
} else { // target station is offline, need to find smallest that is online
gridID := station2grid[stationID]
grid := grids[gridID]
for grid.smallestID < len(grid.stations) && !isOnline[grid.stations[grid.smallestID]] {
grid.smallestID++
}

if grid.smallestID < len(grid.stations) {
res = append(res, grid.stations[grid.smallestID])
} else {
res = append(res, -1)
}
}
} else if v[0] == 2 {
isOnline[v[1]] = false
}
}
return res
}

func dfs(stationID, gridID int, stations *[]int, visited []bool, g [][]int, station2grid map[int]int) {
if visited[stationID] {
return
}
visited[stationID] = true
station2grid[stationID] = gridID
*stations = append(*stations, stationID)
for _, nei := range g[stationID] {
dfs(nei, gridID, stations, visited, g, station2grid)
}
}

type grid struct {
stations []int // stations ordered by id
smallestID int
}
Reply all
Reply to author
Forward
0 new messages