Skip to content

Solutions to LeetCode problems written in Go programming language

License

Notifications You must be signed in to change notification settings

CodeMonkey80s/GoLeetCode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Go LeetCode

Repository with my solutions to various LeetCode problems.

To solve these problems I use functions from Golang Standard Library where applicable...

My main focus is with these areas: Arrays, Hash Tables, Strings, Dynamic Programming.

Tips & Tricks

Read this document for all tips and tricks that are useful for solving these problems.

Solutions

🟩 Easy: 263

🟨 Medium: 40

# Title Solution Level
1 Two Sum link 🟩
3 Longest Substring Without Repeating Characters link 🟨
7 Reverse Integer link 🟨
9 Palindrome Number link 🟩
13 Roman to Integer link 🟩
14 Longest Common Prefix link 🟩
20 Valid Parentheses link 🟩
21 Merge Two Sorted Lists link 🟩
26 Remove Duplicates from Sorted Array link 🟩
27 Remove Element link 🟩
28 Find the Index of the First Occurrence in a String link 🟩
35 Search Insert Position link 🟩
46 Permutations link 🟩
58 Length of Last Word link 🟩
66 Plus One link 🟩
67 Add Binary link 🟩
69 Sqrt(x) link 🟩
70 Climbing Stairs link 🟩
75 Sort Colors link 🟨
78 Subsets link 🟨
83 Remove Duplicates from Sorted List link 🟩
88 Merge Sorted Array link 🟩
94 Binary Tree Inorder Traversal link 🟩
100 Same Tree link 🟩
101 Symmetric Tree link 🟩
104 Maximum Depth of Binary Tree link 🟩
118 Pascal's Triangle link 🟩
119 Pascal's Triangle II link 🟩
121 Best Time to Buy and Sell Stock link 🟩
125 Valid Palindrome link 🟩
136 Single Number link 🟩
151 Reverse Words in a String link 🟨
167 Two Sum II link 🟨
168 Excel Sheet Column Title link 🟩
169 Majority Element link 🟩
171 Excel Sheet Column Number link 🟩
190 Reverse Bits link 🟩
191 Number of 1 Bits link 🟩
198 House Robber link 🟩
205 Isomorphic Strings link 🟩
206 Reverse Linked List link 🟩
217 Contains Duplicate link 🟩
219 Contains Duplicate II link 🟩
228 Summary Ranges link 🟩
242 Valid Anagram link 🟩
257 Binary Tree Paths link 🟩
258 Add Digits link 🟩
268 Missing Number link 🟩
283 Move Zeroes link 🟩
290 Word Pattern link 🟩
303 Range Sum Query - Immutable link 🟩
338 Counting Bits link 🟩
344 Reverse String link 🟩
345 Reverse Vowels of a String link 🟩
349 Intersection of Two Arrays link 🟩
350 Intersection of Two Arrays II link 🟩
383 Ransom Note link 🟩
387 First Unique Character in a String link 🟩
389 Find the Difference link 🟩
392 Is Subsequence link 🟩
401 Binary Watch link 🟩
405 Convert a Number to Hexadecimal link 🟩
412 Fizz Buzz link 🟩
415 Add Strings link 🟩
434 Number of Segments in a String link 🟩
442 Find All Duplicates in an Array link 🟩
448 Find All Numbers Disappeared in an Array link 🟩
451 Sort Characters By Frequency link 🟨
455 Assign Cookies link 🟩
459 Repeated Substring Pattern link 🟩
463 Island Perimeter link 🟩
476 Number Complement link 🟩
482 License Key Formatting link 🟩
485 Max Consecutive Ones link 🟩
500 Keyboard Row link 🟩
509 Fibonacci Number link 🟩
520 Detect Capital link 🟩
520 Detect Capital link 🟩
535 Encode and Decode TinyURL link 🟨
551 Student Attendance Record I link 🟩
557 Reverse Words in a String III link 🟩
599 Minimum Index Sum of Two Lists link 🟩
657 Robot Return to Origin link 🟩
682 Baseball Game link 🟩
693 Binary Number with Alternating Bits link 🟩
709 To Lower Case link 🟩
724 Find Pivot Index link 🟩
746 Min Cost Climbing Stairs link 🟩
762 Prime Number of Set Bits in Binary Representation link 🟩
771 Jewels and Stones link 🟩
796 Rotate String link 🟩
804 Unique Morse Code Words link 🟩
806 Number of Lines To Write String link 🟩
811 Subdomain Visit Count link 🟨
819 Most Common Word link 🟩
821 Shortest Distance to a Character link 🟩
824 Goat Latin link 🟩
830 Positions of Large Groups link 🟩
832 Flipping an Image link 🟩
844 Backspace String Compare link 🟩
861 Score After Flipping Matrix link 🟨
868 Binary Gap link 🟩
884 Uncommon Words from Two Sentences link 🟩
944 Delete Columns to Make Sorted link 🟩
961 N-Repeated Element in Size 2N Array link 🟩
1002 Find Common Characters link 🟩
1047 Remove All Adjacent Duplicates In String link 🟩
1051 Height Checker link 🟩
1078 Occurrences After Bigram link 🟩
1089 Duplicate Zeros link 🟩
1108 Defanging an IP Address link 🟩
1154 Day of the Year link 🟩
1189 Maximum Number of Balloons link 🟩
1207 Unique Number of Occurrences link 🟩
1221 Split a String in Balanced Strings link 🟩
1275 Find Winner on a Tic Tac Toe Game link 🟩
1282 Group the People Given the Group Size They Belong To link 🟨
1287 Element Appearing More Than 25% In Sorted Array link 🟩
1304 Find N Unique Integers Sum up to Zero link 🟩
1309 Decrypt String from Alphabet to Integer Mapping link 🟩
1310 XOR Queries of a Subarray link 🟨
1313 Decompress Run-Length Encoded List link 🟩
1331 Rank Transform of an Array link 🟩
1346 Check If N and Its Double Exist link 🟩
1351 Count Negative Numbers in a Sorted Matrix link 🟩
1360 Number of Days Between Two Dates link 🟩
1365 How Many Numbers Are Smaller Than the Current Number link 🟩
1380 Lucky Numbers in a Matrix link 🟩
1381 Design a Stack with Increment Operation link 🟨
1389 Create Target Array in the Given Order link 🟩
1408 String Matching in an Array link 🟩
1413 Minimum Value to Get Positive Step by Step Sum link 🟩
1431 Kids With the Greatest Number of Candies link 🟩
1436 Destination City link 🟩
1455 Check If a Word Occurs As a Prefix link 🟩
1470 Shuffle the Array link 🟩
1476 Subrectangle Queries link 🟨
1480 Running Sum of 1d Array link 🟩
1486 XOR Operation in an Array link 🟩
1496 Path Crossing link 🟩
1507 Reformat Date link 🟩
1512 Number of Good Pairs link 🟩
1518 Water Bottles link 🟩
1528 Shuffle String link 🟩
1550 Three Consecutive Odds link 🟩
1556 Thousand Separator link 🟩
1561 Maximum Number of Coins You Can Get link 🟨
1572 Matrix Diagonal Sum link 🟩
1588 Sum of All Odd Length Subarrays link 🟩
1592 Rearrange Spaces Between Words link 🟩
1614 Maximum Nesting Depth of the Parentheses link 🟩
1624 Largest Substring Between Two Equal Characters link 🟩
1630 Arithmetic Subarrays link 🟨
1637 Widest Vertical Area Between Two Points Containing No Points link 🟩
1662 Check If Two String Arrays are Equivalent link 🟩
1670 Richest Customer Wealth link 🟩
1678 Goal Parser Interpretation link 🟩
1684 Count the Number of Consistent Strings link 🟩
1704 Determine if String Halves Are Alike link 🟩
1720 Decode XORed Array link 🟩
1742 Maximum Number of Balls in a Box link 🟩
1768 Merge Strings Alternately link 🟩
1769 Minimum Number of Operations to Move All Balls to Each Box link 🟨
1773 Count Items Matching a Rule link 🟩
1796 Second Largest Digit in a String link 🟩
1805 Number of Different Integers in a String link 🟩
1812 Determine Color of a Chessboard Square link 🟩
1816 Truncate Sentence link 🟩
1817 Finidng the Users Active Minutes link 🟨
1827 Minimum Operations to Make the Array Increasing link 🟩
1828 Queries on Number of Points Inside a Circle link 🟨
1832 Check if the Sentence Is Pangram link 🟩
1844 Replace All Digits with Characters link 🟩
1854 Maximum Population Year link 🟩
1859 Sorting the Sentence link 🟩
1863 Sum of All Subset XOR Totals link 🟩
1876 Substrings of Size Three with Distinct Characters link 🟩
1877 Minimize Maximum Pair Sum in Array link 🟨
1880 Check if Word Equals Summation of Two Words link 🟩
1893 Check if All the Integers in a Range Are Covered link 🟩
1910 Remove All Occurrences of a Substring link 🟨
1913 Maximum Product Difference Between Two Pairs link 🟩
1920 Build Array from Permutation link 🟩
1929 Concatenation of Array link 🟩
1941 Check if All Characters Have Equal Number of Occurrences link 🟩
1967 Number of Strings That Appear as Substrings in Word link 🟩
2000 Reverse Prefix of Word link 🟩
2006 Count Number of Pairs With Absolute Difference K link 🟩
2011 Final Value of Variable After Performing Operations link 🟩
2037 Minimum Number of Moves to Seat Everyone link 🟩
2079 Watering Plants link 🟨
2085 Count Common Words With One Occurrence link 🟩
2103 Rings and Rods link 🟩
2114 Maximum Number of Words Found in Sentences link 🟩
2119 A Number After a Double Reversal link 🟩
2120 Execution of All Suffix Instructions Staying in a Grid link 🟨
2129 Capitalize the Title link 🟩
2149 Rearrange Array Elements by Sign link 🟩
2160 Minimum Sum of Four Digit Number After Splitting Digits link 🟩
2169 Count Operations to Obtain Zero link 🟩
2185 Counting Words With a Given Prefix link 🟩
2194 Cells in a Range on an Excel Sheet link 🟩
2215 Find the Difference of Two Arrays link 🟩
2221 Find Triangular Sum of an Array link 🟨
2283 Check if Number Has Equal Digit Count and Digit Value link 🟩
2309 Greatest English Letter in Upper and Lower Case link 🟩
2315 Count Asterisks link 🟩
2325 Decode the Message link 🟩
2373 Largest Local Values in a Matrix link 🟩
2390 Removing Starts From a String link 🟨
2391 Minimum Amount of Time to Collect Garbage link 🟨
2418 Sort the People link 🟩
2428 Maximum Sum of an Hourglass link 🟨
2433 Find The Original Array of Prefix link 🟨
2442 Count Number of Distinct Integer After Reverse Operations link 🟨
2446 Determine if Two Events Have Conflict link 🟩
2451 Odd String Difference link 🟩
2482 Difference Between Ones and Zeros in Row and Column link 🟨
2485 Find the Pivot Integer link 🟩
2496 Maximum Value of a String in an Array link 🟩
2506 Count Pairs of Similar Strings link 🟩
2540 Minimum Common Value link 🟩
2545 Sort the Students by Their Kth Score link 🟨
2553 Separate the Digits in an Array link 🟩
2559 Count Vowel Strings in Ranges link 🟨
2574 Left and Right Sum Differences link 🟩
2586 Count the Number of Vowel Strings in Range link 🟩
2595 Number of Even and Odd Bits link 🟩
2610 Convert an Array Into a 2D Array With Conditions link 🟨
2656 Maximum Sum With Exactly K Elements link 🟩
2696 Minimum String Length After Removing Substrings link 🟩
2716 Minimize String Length link 🟩
2744 Find Maximum Number of String Pairs link 🟩
2778 Sum of Squares of Special Elements link 🟩
2785 Sort Vowels in a String link 🟨
2788 Split Strings by Separator link 🟩
2798 Number of Employees Who Met the Target link 🟩
2810 Faulty Keyboard link 🟩
2824 Count Pairs Whose Sum is Less than Target link 🟩
2828 Check if a String Is an Acronym of Words link 🟩
2843 Count Symmetric Integers link 🟩
2848 Points That Intersect With Cars link 🟩
2859 Sum of Values at Indices With K Set Bits link 🟩
2864 Maximum Odd Binary Number link 🟩
2894 Divisible and Non-divisible Sums Difference link 🟩
2903 Find Indices With Index and Value Difference I link 🟩
2908 Minimum Sum of Mountain Triplets I link 🟩
2914 Minimum Number of Changes to Make Binary String Beautiful link 🟨
2917 Find the K-or of an Array link 🟩
2932 Maximum Strong Pair XOR I link 🟩
2942 Find Words Containing Character link 🟩
2960 Count Tested Devices After Test Operations link 🟩
2974 Minimum Number Game link 🟩
3005 Count Elements With Maximum Frequency link 🟩
3019 Number of Changing Keys link 🟩
3028 Ant on the Boundary link 🟩
3033 Modify the Matrix link 🟩
3046 Split the Array link 🟩
3065 Minimum Operations to Exceed Threshold Value I link 🟩
3074 Apple Redistribution into Boxes link 🟩
3095 Shortest Subarray With OR at Least K I link 🟩
3099 Harshad Number link 🟩
3110 Score of String link 🟩
3120 Count the Number of Special Characters I link 🟩
3136 Valid Word link 🟩
3151 Special Array I link 🟩
3158 Find the XOR of Numbers Which Appear Twice link 🟩
3162 Find the Number of Good Pairs I link 🟩
3163 String Compression III link 🟨
3168 Minimum Number of Chairs in a Waiting Room link 🟩
3174 Clear Digits link 🟩
3194 Minimum Average of Smallest and Largest Elements link 🟩
3195 Find the Minimum Area to Cover All Ones I link 🟨
3206 Alternating Groups I link 🟩
3210 Find the Encrypted String link 🟩
3216 Lexicographically Smallest String After a Swap link 🟩
3226 Number of Bit Changes to Make Two Integers Equal link 🟩
3232 Find if Digit Game Can Be Won link 🟩
3242 Design Neighbor Sum Service link 🟩
3248 Snake in Matrix link 🟩
3258 Count Substrings That Satisfy K-Constraint I link 🟩
3264 Final Array State After K Multiplication Operations I link 🟩
3271 Hash Divided String link 🟨
3289 The Two Sneaky Numbers of Digitville link 🟩
3280 Convert Date to Binary link 🟩
3285 Find Indices of Stable Mountains link 🟩
3270 Find the Key of the Numbers link 🟩
3274 Check if Two Chessboard Squares Have the Same Color link 🟩
3300 Minimum Element After Replacement With Digit Sum link 🟩
3304 Find the K-th Character in String Game I link 🟩
3324 Find the Sequence of Strings Appeared on the Screen link 🟨
3340 Check Balanced String link 🟩
3354 Make Array Elements Equal to Zero link 🟩
3360 Stone Removal Game link 🟩
3370 Smallest Number With All Set Bits link 🟩
3379 Transformet Array link 🟩
3386 Button with Longest Push Time link 🟩
3392 Count Subarrays of Length Three With a Condition link 🟩
3396 Minimum Number of Operations to Make Elements in Array Distinct link 🟩
3402 Minimum Operations to Make Columns Strictly Increasing link 🟩
3407 Substring Matching Pattern link 🟩
3412 Find Mirror Score of a String link 🟨
3417 Zigzag Grid Traversal With Skip link 🟩
3423 Maximum Difference Between Adjacent Elements in a Circular Array link 🟩

Static Analysis

Run golangci-lint command. There is a hidden configuration file for this tool inside root directory .golangci.yml.

$ golangci-lint --color always run --verbose ./...

Testing

For every problem I have used test file to verify the solution with bunch of test cases.

You can run these tests with command:

$ go test -v ./...

Benchmarking

Many solutions also contain benchmarks.

$ go test -bench=. -benchmem ./1---Two-Sum
goos: linux
goarch: amd64
cpu: 13th Gen Intel(solutions/R) Core(solutions/TM) i7-13700K
Benchmark_twoSum_Iterations-24    	100000000	        13.83 ns/op	      16 B/op	       1 allocs/op
Benchmark_twoSum_Map-24           	43644519	        25.72 ns/op	      16 B/op	       1 allocs/op
PASS

License

About

Solutions to LeetCode problems written in Go programming language

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages