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 / partition-labels.go
Created January 3, 2026 06:18
763. Partition Labels
// https://leetcode.com/problems/partition-labels/
//
// Time: O(n)
// Space: O(1)
//
// n = number of letters in string
// .................... //
func partitionLabels(s string) []int {
@rtsoy
rtsoy / container-with-most-water.go
Created January 3, 2026 05:54
11. Container With Most Water
// https://leetcode.com/problems/container-with-most-water/
//
// Time: O(n)
// Space: O(1)
//
// n = number of elements in array
// .................... //
func maxArea(height []int) int {
@rtsoy
rtsoy / merge-intervals.go
Created January 3, 2026 05:36
56. Merge Intervals
// https://leetcode.com/problems/merge-intervals/
//
// Time: O(n log n)
// Space: O(n)
//
// n = number of intervals
// .................... //
func merge(intervals [][]int) [][]int {
@rtsoy
rtsoy / top-k-frequent-elements.go
Created January 3, 2026 05:24
347. Top K Frequent Elements
// https://leetcode.com/problems/top-k-frequent-elements/
//
// Time: O(n log k)
// Space: O(n)
//
// n - number of unique elements in array
// .................... //
type item struct {
@rtsoy
rtsoy / top-k-frequent-words.go
Created January 3, 2026 05:14
692. Top K Frequent Words
// https://leetcode.com/problems/top-k-frequent-words/
//
// Time: O(n log k)
// Space: O(n)
//
// n = number of unique words in array
// .................... //
type item struct {
@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 {
@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 / 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 / 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 / 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 {