Skip to content

Instantly share code, notes, and snippets.

View rtsoy's full-sized avatar
:octocat:

Roman rtsoy

:octocat:
  • Astana, Kazakhstan
View GitHub Profile
@rtsoy
rtsoy / merge-k-sorted-lists.go
Last active January 1, 2026 13:59
23. Merge k Sorted Lists
// https://leetcode.com/problems/merge-k-sorted-lists
//
// Time: O(N log k)
// Space: O(k)
//
// k = len(lists)
// N = total number of nodes across all lists
// .................... //
@rtsoy
rtsoy / add-two-numbers.go
Created January 1, 2026 14:12
2. Add Two Numbers
// https://leetcode.com/problems/add-two-numbers/
//
// Time: O(N)
// Space: O(N)
//
// N = number of nodes in the longer list
// .................... //
/**
@rtsoy
rtsoy / reverse-linked-list.go
Created January 1, 2026 14:22
206. Reverse Linked List
// https://leetcode.com/problems/reverse-linked-list/
//
// Time: O(N)
// Space: O(1)
//
// N = number of nodes in the list
// .................... //
/**
@rtsoy
rtsoy / search-a-2d-matrix.go
Created January 1, 2026 14:43
74. Search a 2D Matrix
// https://leetcode.com/problems/search-a-2d-matrix/
//
// Time: O(log(m*n))
// Space: O(1)
//
// m = number of rows
// n = number of columns
// .................... //
@rtsoy
rtsoy / search-in-rotated-sorted-array.go
Last active January 1, 2026 15:22
33. Search in Rotated Sorted Array
// https://leetcode.com/problems/search-in-rotated-sorted-array/
//
// Time: O(log n)
// Space: O(1)
//
// n = number of elements in the array
// .................... //
func search(nums []int, target int) int {
@rtsoy
rtsoy / search-in-rotated-sorted-array-ii.go
Last active January 1, 2026 17:22
81. Search in Rotated Sorted Array II
// https://leetcode.com/problems/search-in-rotated-sorted-array-ii/
//
// Time: O(log n) average
// Space: O(1)
//
// n = number of elements in the array
// .................... //
func search(nums []int, target int) bool {
@rtsoy
rtsoy / single-number.go
Created January 2, 2026 07:42
136. Single Number
// https://leetcode.com/problems/single-number/
//
// Time: O(n)
// Space: O(1)
//
// n - number of elements in array
// .................... //
func singleNumber(nums []int) int {
@rtsoy
rtsoy / 4sum.go
Created January 2, 2026 08:24
18. 4Sum
// https://leetcode.com/problems/4sum/
//
// Time: O(n^3)
// Space: O(1)
//
// n = number of elements in array
// .................... //
func fourSum(nums []int, target int) [][]int {
@rtsoy
rtsoy / find-all-anagrams-in-a-string.go
Created January 2, 2026 08:46
438. Find All Anagrams in a String
// https://leetcode.com/problems/find-all-anagrams-in-a-string/
//
// Time: O(n)
// Space: O(1)
//
// n - number of elements in array
// .................... //
func findAnagrams(s string, p string) []int {
@rtsoy
rtsoy / number-of-islands.go
Created January 2, 2026 15:19
200. Number of Islands
// https://leetcode.com/problems/number-of-islands/
//
// Time: O(n*m)
// Space: O(n*m)
//
// n = number of rows, m = number of columns
// .................... //
func numIslands(grid [][]byte) int {