├── 1217-relative-sort-array ├── 1217-relative-sort-array.go └── README.md ├── 1436-destination-city ├── README.md └── destination-city.go ├── 1684-count-the-number-of-consistent-strings ├── README.md └── count-the-number-of-consistent-strings.go ├── 175-combine-two-tables ├── README.md └── combine-two-tables.sql ├── 2235-add-two-integers ├── README.md └── add-two-integers.go ├── 2248-intersection-of-multiple-arrays ├── README.md └── intersection-of-multiple-arrays.go ├── 2278-percentage-of-letter-in-string ├── README.md └── percentage-of-letter-in-string.go ├── 228-summary-ranges ├── README.md └── summary-ranges.go ├── 2413-smallest-even-multiple ├── README.md └── smallest-even-multiple.go ├── 2469-convert-the-temperature ├── README.md └── convert-the-temperature.go ├── 2894-divisible-and-non-divisible-sums-difference ├── README.md └── divisible-and-non-divisible-sums-difference.go ├── 3028-ant-on-the-boundary ├── README.md └── ant-on-the-boundary.go ├── 3079-find-the-sum-of-encrypted-integers ├── README.md └── find-the-sum-of-encrypted-integers.go ├── 3248-snake-in-matrix ├── README.md └── snake-in-matrix.go ├── 3274-check-if-two-chessboard-squares-have-the-same-color ├── README.md └── check-if-two-chessboard-squares-have-the-same-color.go ├── 3289-the-two-sneaky-numbers-of-digitville ├── README.md └── the-two-sneaky-numbers-of-digitville.go ├── 3300-minimum-element-after-replacement-with-digit-sum ├── README.md └── minimum-element-after-replacement-with-digit-sum.go ├── 3340-check-balanced-string ├── README.md └── check-balanced-string.go ├── 3345-smallest-divisible-digit-product-i ├── README.md └── smallest-divisible-digit-product-i.go ├── 3370-smallest-number-with-all-set-bits ├── README.md └── smallest-number-with-all-set-bits.go ├── 412-fizz-buzz ├── README.md └── fizz-buzz.go ├── 58-length-of-last-word ├── README.md └── length-of-last-word.go ├── 88-merge-sorted-array ├── README.md └── merge-sorted-array.go ├── C ├── Leetcode 1185 Day of the Week.c └── Leetcode 283 Move Zeroes.c ├── Golang ├── 100-same-tree │ ├── README.md │ └── same-tree.go ├── 110-balanced-binary-tree │ ├── README.md │ └── balanced-binary-tree.go ├── 1137-height-checker │ ├── README.md │ └── height-checker.go ├── 1146-greatest-common-divisor-of-strings │ ├── README.md │ └── greatest-common-divisor-of-strings.go ├── 118-pascals-triangle │ ├── README.md │ └── pascals-triangle.go ├── 119-pascals-triangle-ii │ ├── README.md │ └── pascals-triangle-ii.go ├── 1217-relative-sort-array │ ├── README.md │ └── relative-sort-array.go ├── 1231-replace-elements-with-greatest-element-on-right-side │ ├── README.md │ └── replace-elements-with-greatest-element-on-right-side.go ├── 1236-n-th-tribonacci-number │ ├── README.md │ └── n-th-tribonacci-number.go ├── 125-valid-palindrome │ ├── README.md │ └── valid-palindrome.go ├── 1421-find-numbers-with-even-number-of-digits │ ├── README.md │ └── find-numbers-with-even-number-of-digits.go ├── 145-binary-tree-postorder-traversal │ ├── README.md │ └── binary-tree-postorder-traversal.go ├── 1462-list-the-products-ordered-in-a-period │ ├── README.md │ └── list-the-products-ordered-in-a-period.sql ├── 1496-lucky-numbers-in-a-matrix │ ├── README.md │ └── lucky-numbers-in-a-matrix.go ├── 1542-consecutive-characters │ ├── README.md │ └── consecutive-characters.go ├── 1547-destination-city │ ├── README.md │ └── destination-city.go ├── 1614-maximum-nesting-depth-of-the-parentheses │ ├── README.md │ └── maximum-nesting-depth-of-the-parentheses.go ├── 1656-count-good-triplets │ ├── README.md │ └── count-good-triplets.go ├── 167-two-sum-ii-input-array-is-sorted │ └── two-sum-ii-input-array-is-sorted.go ├── 169-majority-element │ ├── README.md │ └── majority-element.go ├── 1786-count-the-number-of-consistent-strings │ ├── README.md │ └── count-the-number-of-consistent-strings.go ├── 189-rotate-array │ ├── README.md │ └── rotate-array.go ├── 1894-merge-strings-alternately │ ├── README.md │ └── merge-strings-alternately.go ├── 1952-three-divisors │ ├── README.md │ └── three-divisors.go ├── 1987-substrings-of-size-three-with-distinct-characters │ ├── README.md │ └── substrings-of-size-three-with-distinct-characters.go ├── 2010-check-if-word-equals-summation-of-two-words │ ├── README.md │ └── check-if-word-equals-summation-of-two-words.go ├── 2032-largest-odd-number-in-string │ ├── README.md │ └── largest-odd-number-in-string.go ├── 2037-count-square-sum-triples │ ├── README.md │ └── count-square-sum-triples.go ├── 2053-check-if-all-characters-have-equal-number-of-occurrences │ ├── README.md │ └── check-if-all-characters-have-equal-number-of-occurrences.go ├── 206-reverse-linked-list │ ├── README.md │ └── reverse-linked-list.go ├── 2132-convert-1d-array-into-2d-array │ ├── README.md │ └── convert-1d-array-into-2d-array.go ├── 2148-minimum-number-of-moves-to-seat-everyone │ ├── README.md │ └── minimum-number-of-moves-to-seat-everyone.go ├── 2181-smallest-index-with-equal-value │ ├── README.md │ └── smallest-index-with-equal-value.go ├── 2219-maximum-number-of-words-found-in-sentences │ ├── README.md │ └── maximum-number-of-words-found-in-sentences.go ├── 2269-count-elements-with-strictly-smaller-and-greater-elements │ ├── README.md │ └── count-elements-with-strictly-smaller-and-greater-elements.go ├── 2271-rearrange-array-elements-by-sign │ ├── README.md │ └── rearrange-array-elements-by-sign.go ├── 228-summary-ranges │ ├── README.md │ └── summary-ranges.go ├── 2308-divide-array-into-equal-pairs │ ├── README.md │ └── divide-array-into-equal-pairs.go ├── 2331-intersection-of-multiple-arrays │ ├── README.md │ └── intersection-of-multiple-arrays.go ├── 2365-percentage-of-letter-in-string │ ├── README.md │ └── percentage-of-letter-in-string.go ├── 237-delete-node-in-a-linked-list │ ├── README.md │ └── delete-node-in-a-linked-list.go ├── 2383-add-two-integers │ ├── README.md │ └── add-two-integers.c ├── 2427-number-of-common-factors │ ├── README.md │ └── number-of-common-factors.go ├── 2454-largest-local-values-in-a-matrix │ ├── README.md │ └── largest-local-values-in-a-matrix.go ├── 2455-average-value-of-even-numbers-that-are-divisible-by-three │ ├── README.md │ └── average-value-of-even-numbers-that-are-divisible-by-three.go ├── 2486-most-frequent-even-element │ ├── README.md │ └── most-frequent-even-element.go ├── 2502-sort-the-people │ ├── README.md │ └── sort-the-people.go ├── 2525-count-number-of-distinct-integers-after-reverse-operations │ ├── README.md │ └── count-number-of-distinct-integers-after-reverse-operations.go ├── 2614-maximum-count-of-positive-integer-and-negative-integer │ ├── README.md │ └── maximum-count-of-positive-integer-and-negative-integer.go ├── 2654-count-the-number-of-vowel-strings-in-range │ ├── README.md │ └── count-the-number-of-vowel-strings-in-range.go ├── 27-remove-element │ ├── README.md │ └── remove-element.go ├── 2824-check-if-the-number-is-fascinating │ ├── README.md │ └── check-if-the-number-is-fascinating.go ├── 2825-minimize-string-length │ ├── README.md │ └── minimize-string-length.go ├── 2887-sort-vowels-in-a-string │ ├── Notes.md │ ├── README.md │ └── sort-vowels-in-a-string.go ├── 292-nim-game │ ├── README.md │ └── nim-game.go ├── 3-longest-substring-without-repeating-characters │ ├── README.md │ └── longest-substring-without-repeating-characters.go ├── 3154-maximum-value-of-an-ordered-triplet-i │ ├── README.md │ └── maximum-value-of-an-ordered-triplet-i.go ├── 3165-find-indices-with-index-and-value-difference-i │ ├── README.md │ └── find-indices-with-index-and-value-difference-i.go ├── 3193-maximum-strong-pair-xor-i │ ├── README.md │ └── maximum-strong-pair-xor-i.go ├── 3199-distribute-candies-among-children-i │ ├── README.md │ └── distribute-candies-among-children-i.go ├── 3206-find-common-elements-between-two-arrays │ ├── README.md │ └── find-common-elements-between-two-arrays.go ├── 3220-count-tested-devices-after-test-operations │ ├── README.md │ └── count-tested-devices-after-test-operations.go ├── 3221-find-the-peaks │ ├── README.md │ └── find-the-peaks.go ├── 3361-latest-time-you-can-obtain-after-replacing-characters │ ├── README.md │ └── latest-time-you-can-obtain-after-replacing-characters.go ├── 3367-find-the-sum-of-encrypted-integers │ ├── README.md │ └── find-the-sum-of-encrypted-integers.go ├── 3373-maximum-prime-difference │ ├── README.md │ └── maximum-prime-difference.go ├── 3383-taking-maximum-energy-from-the-mystic-dungeon │ ├── README.md │ └── taking-maximum-energy-from-the-mystic-dungeon.go ├── 3396-valid-word │ ├── README.md │ └── valid-word.go ├── 3397-find-the-integer-added-to-array-i │ ├── README.md │ └── find-the-integer-added-to-array-i.go ├── 3398-make-a-square-with-the-same-color │ ├── README.md │ └── make-a-square-with-the-same-color.go ├── 3405-count-the-number-of-special-characters-ii │ ├── README.md │ └── count-the-number-of-special-characters-ii.go ├── 3408-count-the-number-of-special-characters-i │ ├── README.md │ └── count-the-number-of-special-characters-i.go ├── 3415-check-if-grid-satisfies-conditions │ ├── README.md │ ├── check-if-grid-satisfies-conditions.go │ └── check-if-grid-satisfies-conditions.java ├── 3416-sum-of-digit-differences-of-all-pairs │ ├── README.md │ └── sum-of-digit-differences-of-all-pairs.go ├── 3418-count-pairs-that-form-a-complete-day-ii │ ├── README.md │ └── count-pairs-that-form-a-complete-day-ii.go ├── 3427-special-array-ii │ ├── README.md │ └── special-array-ii.go ├── 3434-find-the-number-of-distinct-colors-among-the-balls │ ├── README.md │ └── find-the-number-of-distinct-colors-among-the-balls.go ├── 3447-clear-digits │ ├── README.md │ └── clear-digits.go ├── 3450-find-the-child-who-has-the-ball-after-k-seconds │ ├── README.md │ └── find-the-child-who-has-the-ball-after-k-seconds.go ├── 3463-alternating-groups-i │ ├── README.md │ └── alternating-groups-i.go ├── 3468-find-the-encrypted-string │ ├── README.md │ └── find-the-encrypted-string.go ├── 3469-maximum-height-of-a-triangle │ ├── README.md │ └── maximum-height-of-a-triangle.go ├── 3471-minimum-average-of-smallest-and-largest-elements │ ├── README.md │ └── minimum-average-of-smallest-and-largest-elements.go ├── 3501-delete-nodes-from-linked-list-present-in-array │ ├── README.md │ └── delete-nodes-from-linked-list-present-in-array.go ├── 3508-number-of-bit-changes-to-make-two-integers-equal │ ├── README.md │ └── number-of-bit-changes-to-make-two-integers-equal.go ├── 3511-find-the-winning-player-in-coin-game │ ├── README.md │ └── find-the-winning-player-in-coin-game.go ├── 3515-find-if-digit-game-can-be-won │ ├── README.md │ └── find-if-digit-game-can-be-won.go ├── 3519-find-the-number-of-winning-players │ ├── README.md │ └── find-the-number-of-winning-players.go ├── 3533-snake-in-matrix │ ├── README.md │ └── snake-in-matrix.go ├── 3553-check-if-two-chessboard-squares-have-the-same-color │ ├── README.md │ └── check-if-two-chessboard-squares-have-the-same-color.go ├── 3555-final-array-state-after-k-multiplication-operations-i │ ├── README.md │ └── final-array-state-after-k-multiplication-operations-i.go ├── 3567-convert-date-to-binary │ ├── README.md │ └── convert-date-to-binary.go ├── 3568-find-the-key-of-the-numbers │ ├── README.md │ └── find-the-key-of-the-numbers.go ├── 3581-the-two-sneaky-numbers-of-digitville │ ├── README.md │ └── the-two-sneaky-numbers-of-digitville.go ├── 3582-find-indices-of-stable-mountains │ ├── README.md │ └── find-indices-of-stable-mountains.go ├── 3606-minimum-element-after-replacement-with-digit-sum │ ├── README.md │ └── minimum-element-after-replacement-with-digit-sum.go ├── 3636-check-balanced-string │ ├── README.md │ └── check-balanced-string.go ├── 378-kth-smallest-element-in-a-sorted-matrix │ ├── README.md │ └── kth-smallest-element-in-a-sorted-matrix.go ├── 4-median-of-two-sorted-arrays │ ├── README.md │ └── median-of-two-sorted-arrays.go ├── 414-third-maximum-number │ ├── README.md │ └── third-maximum-number.go ├── 48-rotate-image │ ├── README.md │ └── rotate-image.go ├── 485-max-consecutive-ones │ ├── README.md │ └── max-consecutive-ones.go ├── 496-next-greater-element-i │ ├── README.md │ └── next-greater-element-i.go ├── 50-powx-n │ ├── README.md │ └── powx-n.go ├── 500-keyboard-row │ ├── README.md │ └── keyboard-row.go ├── 507-perfect-number │ ├── README.md │ └── perfect-number.go ├── 521-longest-uncommon-subsequence-i │ ├── README.md │ └── longest-uncommon-subsequence-i.go ├── 53-maximum-subarray │ ├── README.md │ └── maximum-subarray.go ├── 567-permutation-in-string │ ├── README.md │ └── permutation-in-string.go ├── 58-length-of-last-word │ ├── README.md │ └── length-of-last-word.go ├── 620-not-boring-movies │ ├── README.md │ └── not-boring-movies.sql ├── 75-sort-colors │ ├── README.md │ └── sort-colors.go ├── 88-merge-sorted-array │ ├── README.md │ └── merge-sorted-array.go ├── 890-lemonade-change │ ├── README.md │ └── lemonade-change.go ├── 9-palindrome-number │ ├── README.md │ └── palindrome-number.go ├── 920-uncommon-words-from-two-sentences │ ├── README.md │ └── uncommon-words-from-two-sentences.go ├── 94-binary-tree-inorder-traversal │ ├── README.md │ └── binary-tree-inorder-traversal.go ├── Leetccode 3028. Ant on the Boundary.go ├── Leetcode 344 Reverse String Golang Solution.go ├── Leetcode 1 Two Sum.go ├── Leetcode 100 Same Tree.go ├── Leetcode 104 Maximum Depth of Binary Tree.go ├── Leetcode 1089. Duplicate Zeros.go ├── Leetcode 1108 Defanging an IP Address Golang Solution.go ├── Leetcode 1207. Unique Number of Occurrences.go ├── Leetcode 121. Best Time to Buy and Sell Stock.go ├── Leetcode 1281 Subtract the Product and Sum of Digits of an Integer.go ├── Leetcode 1282 Group the People Given the Group Size They Belong To.go ├── Leetcode 1290 Convert Binary Number in a Linked List to Integer.go ├── Leetcode 1291. Sequential Digits.go ├── Leetcode 1302. Deepest Leaves Sum.go ├── Leetcode 1304 Find N Unique Integers Sum up to Zero.go ├── Leetcode 1313. Decompress Run-Length Encoded List.go ├── Leetcode 1317. Convert Integer to the Sum of Two No-Zero Integers.go ├── Leetcode 1347. Minimum Number of Steps to Make Two Strings Anagram.go ├── Leetcode 1351. Count Negative Numbers in a Sorted Matrix.go ├── Leetcode 1365 How Many Numbers Are Smaller Than the Current Number.go ├── Leetcode 1370 Increasing Decreasing String.go ├── Leetcode 1385. Find the Distance Value Between Two Arrays.go ├── Leetcode 1389 Create Target Array in the Given Order Golang Solution.go ├── Leetcode 141 Linked List Cycle.go ├── Leetcode 1431. Kids With the Greatest Number of Candies.go ├── Leetcode 144 Binary Tree Preorder Traversal.go ├── Leetcode 145 Binary Tree Postorder Traversal.go ├── Leetcode 1450. Number of Students Doing Homework at a Given Time Golang Solution.go ├── Leetcode 1470 Shuffle the Array Golang Solution.go ├── Leetcode 1481. Least Number of Unique Integers after K Removals.go ├── Leetcode 1486 XOR Operation in an Array Golang Solution.go ├── Leetcode 1486 XOR Operation in an Array.go ├── Leetcode 1496 Path Crossing.go ├── Leetcode 1502 Can Make Arithmetic Progression From Sequence Golang Solution.go ├── Leetcode 1507 Reformat Date Golang SOlution.go ├── Leetcode 1512 Number of Good Pairs.go ├── Leetcode 1523 Count Odd Numbers in an Interval Range Golang Solutions.go ├── Leetcode 1528. Shuffle String.go ├── Leetcode 1556 Thousand Separator Golang Solution.go ├── Leetcode 1588 Sum of All Odd Length Subarrays.go ├── Leetcode 1592 Rearrange Spaces Between Words Golang Solution.go ├── Leetcode 160 Intersection of Two Linked Lists.go ├── Leetcode 1614. Maximum Nesting Depth of the Parentheses.go ├── Leetcode 1624 Largest Substring Between Two Equal Characters.go ├── Leetcode 1657. Determine if Two Strings Are Close.go ├── Leetcode 1662. Check If Two String Arrays are Equivalent.go ├── Leetcode 1672 Richest Customer Wealth.go ├── Leetcode 1678 Goal Parser Interpretation.go ├── Leetcode 1688 Count of Matches in Tournament.go ├── Leetcode 1689 Partitioning Into Minimum Number Of Deci-Binary Numbers.go ├── Leetcode 169 Majority Element.go ├── Leetcode 1704. Determine if String Halves Are Alike.go ├── Leetcode 1710. Maximum Units on a Truck.go ├── Leetcode 1720. Decode XORed Array.go ├── Leetcode 1748 Sum of Unique Elements.go ├── Leetcode 1773. Count Items Matching a Rule.go ├── Leetcode 1816. Truncate Sentence.go ├── Leetcode 1832 Check if the Sentence Is Pangram.go ├── Leetcode 19 Remove Nth Node From End of List.go ├── Leetcode 191. Number of 1 Bits.go ├── Leetcode 1913 Maximum Product Difference Between Two Pairs.go ├── Leetcode 1920 Build Array from Permutation Golang Solution.go ├── Leetcode 1929 Concatenation of Array Golang Solution.go ├── Leetcode 1941 Check if All Characters Have Equal Number of Occurrences.go ├── Leetcode 1952. Three Divisors.go ├── Leetcode 1979. Find Greatest Common Divisor of Array.go ├── Leetcode 20 Valid Parentheses.go ├── Leetcode 2006 Count Number of Pairs With Absolute Difference K.go ├── Leetcode 2011 Final Value of Variable After Performing Operations.go ├── Leetcode 202 Happy Number.go ├── Leetcode 205 Isomorphic Strings.go ├── Leetcode 206. Reverse Linked List.go ├── Leetcode 2089 Find Target Indices After Sorting Array.go ├── Leetcode 2095 Delete the Middle Node of a Linked List.go ├── Leetcode 2108. Find First Palindromic String in the Array.go ├── Leetcode 2114. Maximum Number of Words Found in Sentences.go ├── Leetcode 2119 A Number After a Double Reversal.go ├── Leetcode 2124 Check if All A's Appears Before All B's.go ├── Leetcode 2125 Number of Laser Beams in a Bank.go ├── Leetcode 2154. Keep Multiplying Found Values by Two.go ├── Leetcode 217 Contains Duplicate.go ├── Leetcode 2176 Count Equal and Divisible Pairs in an Array.go ├── Leetcode 2180 Count Integers With Even Digit Sum.go ├── Leetcode 2186. Minimum Number of Steps to Make Two Strings Anagram II.go ├── Leetcode 219. Contains Duplicate II.go ├── Leetcode 2190. Most Frequent Number Following Key In an Array.go ├── Leetcode 2215. Find the Difference of Two Arrays.go ├── Leetcode 2235 Add Two Integers.go ├── Leetcode 2273. Find Resultant Array After Removing Anagrams.go ├── Leetcode 231. Power of Two.go ├── Leetcode 234. Palindrome Linked List.go ├── Leetcode 2341. Maximum Number of Pairs in Array.go ├── Leetcode 2351 First Letter to Appear Twice.go ├── Leetcode 2357 Make Array Zero by Subtracting Equal Amounts.go ├── Leetcode 2367 Number of Arithmetic Triplets.go ├── Leetcode 2396. Strictly Palindromic Number.go ├── Leetcode 2404. Most Frequent Even Element.go ├── Leetcode 2413 Smallest Even Multiple.go ├── Leetcode 242 Valid Anagram.go ├── Leetcode 2427 Number of Common Factors.go ├── Leetcode 2433 Find The Original Array of Prefix Xor.go ├── Leetcode 2441 Largest Positive Integer That Exists With Its Negative.go ├── Leetcode 2455. Average Value of Even Numbers That Are Divisible by Three.go ├── Leetcode 2469 Convert the Temperature Golang Solution.go ├── Leetcode 2475 Number of Unequal Triplets in Array.go ├── Leetcode 2496. Maximum Value of a String in an Array.go ├── Leetcode 2535 Difference Between Element Sum and Digit Sum of an Array.go ├── Leetcode 2540. Minimum Common Value.go ├── Leetcode 2544 Alternating Digit Sum.go ├── Leetcode 2574. Left and Right Sum Differences.go ├── Leetcode 26 Remove Duplicates from Sorted Array.go ├── Leetcode 2610 Convert an Array Into a 2D Array With Conditions.go ├── Leetcode 268. Missing Number.go ├── Leetcode 2706 Buy Two Chocolates.go ├── Leetcode 2769 Find the Maximum Achievable Number.go ├── Leetcode 2798 Number of Employees Who Met the Target.go ├── Leetcode 28 Find the Index of the First Occurrence in a String.go ├── Leetcode 2807 Insert Greatest Common Divisors in Linked List.go ├── Leetcode 2824 Count Pairs Whose Sum is Less than Target.go ├── Leetcode 2828 Check if a String Is an Acronym of Words.go ├── Leetcode 2833. Furthest Point From Origin.go ├── Leetcode 2859. Sum of Values at Indices With K Set Bits.go ├── Leetcode 2864. Maximum Odd Binary Number.go ├── Leetcode 287 Find the Duplicate Number.go ├── Leetcode 2870 Minimum Number of Operations to Make Array Empty.go ├── Leetcode 2894 Divisible and Non-divisible Sums Difference.go ├── Leetcode 2942 Find Words Containing Character.go ├── Leetcode 2965. Find Missing and Repeated Values.go ├── Leetcode 2974. Minimum Number Game.go ├── Leetcode 3000. Maximum Area of Longest Diagonal Rectangle.go ├── Leetcode 3005. Count Elements With Maximum Frequency.go ├── Leetcode 3090. Maximum Length Substring With Two Occurrences.go ├── Leetcode 3099. Harshad Number.go ├── Leetcode 3115. Maximum Prime Difference.go ├── Leetcode 326. Power of Three.go ├── Leetcode 342. Power of Four.go ├── Leetcode 349. Intersection of Two Arrays.go ├── Leetcode 35 Search Insert Position.go ├── Leetcode 350. Intersection of Two Arrays II.go ├── Leetcode 367. Valid Perfect Square.go ├── Leetcode 380. Insert Delete GetRandom O(1).go ├── Leetcode 383. Ransom Note.go ├── Leetcode 387. First Unique Character in a String.go ├── Leetcode 389 Find the Difference Golang Solution.go ├── Leetcode 412 Fizz Buzz Golang.go ├── Leetcode 414. Third Maximum Number.go ├── Leetcode 438. Find All Anagrams in a String.go ├── Leetcode 442. Find All Duplicates in an Array.go ├── Leetcode 455 Assign Cookies.go ├── Leetcode 46. Permutations.go ├── Leetcode 49. Group Anagrams.go ├── Leetcode 507. Perfect Number.go ├── Leetcode 509. Fibonacci Number.go ├── Leetcode 561. Array Partition.go ├── Leetcode 567. Permutation in String.go ├── Leetcode 575 Distribute Candies.go ├── Leetcode 58 Length of Last Word.go ├── Leetcode 628 Maximum Product of Three Numbers.go ├── Leetcode 643. Maximum Average Subarray I.go ├── Leetcode 645 Set Mismatch.go ├── Leetcode 657. Robot Return to Origin.go ├── Leetcode 66 Plus One.go ├── Leetcode 7 Reverse Integer.go ├── Leetcode 70. Climbing Stairs.go ├── Leetcode 704 Binary Search.go ├── Leetcode 707 Design Linked List.go ├── Leetcode 709 To Lower Case Inbuilt.go ├── Leetcode 709 To Lower Case.go ├── Leetcode 744 Find Smallest Letter Greater Than Target.go ├── Leetcode 771 Jewels and Stones.go ├── Leetcode 872 Leaf-Similar Trees.go ├── Leetcode 876 Middle of the Linked List.go ├── Leetcode 896. Monotonic Array.go ├── Leetcode 9 Palindrome Number.go ├── Leetcode 938 Range Sum of BST.go ├── Leetcode 94 Binary Tree Inorder Traversal.go ├── Leetcode 961. N-Repeated Element in Size 2N Array.go └── Leetcode 977. Squares of a Sorted Array.go ├── Javascript └── test.md ├── LICENSE ├── LeetSync2-Metadata.txt ├── README.md ├── SQL ├── 1068. Product Sales Analysis I.sql ├── 1148. Article Views I.sql ├── 1581. Customer Who Visited but Did Not Make Any Transactions.sql ├── 1683. Invalid Tweets.sql ├── 1757. Recyclable and Low Fat Products.sql ├── 2356. Number of Unique Subjects Taught by Each Teacher.sql ├── 584. Find Customer Referee.go ├── 595. Big Countries.sql └── Leetcode 1378. Replace Employee ID With The Unique Identifier.sql └── School └── Sum of Series ├── README.md └── sum-of-series.py /1217-relative-sort-array/1217-relative-sort-array.go: -------------------------------------------------------------------------------- 1 | func relativeSortArray(arr1 []int, arr2 []int) []int { 2 | idxArr1 := make([]int, 1001) 3 | size1, size2 := len(arr1), len(arr2) 4 | output := make([]int, 0, (size1 + size2)) 5 | for _, num := range arr1 { 6 | idxArr1[num]++ 7 | } 8 | for _, num := range arr2 { 9 | output = append(output, num) 10 | for idxArr1[num] > 1 { 11 | output = append(output, num) 12 | idxArr1[num]-- 13 | } 14 | idxArr1[num]-- 15 | } 16 | for idx, num := range idxArr1 { 17 | for i := 1; i <= num; i++ { 18 | output = append(output, idx) 19 | } 20 | } 21 | return output 22 | } -------------------------------------------------------------------------------- /1436-destination-city/destination-city.go: -------------------------------------------------------------------------------- 1 | func destCity(paths [][]string) string { 2 | destMap := make(map[string]string) 3 | for _, val := range paths { 4 | destMap[val[0]] = val[1] 5 | } 6 | // fmt.Println(destMap) 7 | // init := paths[0][0] 8 | // fmt.Println(init) 9 | for _, val := range destMap { 10 | if _, exists := destMap[val]; !exists { 11 | return val 12 | } 13 | // init = destMap[init] 14 | // fmt.Println(init) 15 | } 16 | return "" 17 | } -------------------------------------------------------------------------------- /1684-count-the-number-of-consistent-strings/count-the-number-of-consistent-strings.go: -------------------------------------------------------------------------------- 1 | func countConsistentStrings(allowed string, words []string) int { 2 | allowedArr := make([]bool, 26) 3 | var count int 4 | for _, char := range allowed { 5 | allowedArr[char - 'a'] = true 6 | } 7 | for _, word := range words { 8 | var flag bool 9 | for _, char := range word { 10 | if !allowedArr[char - 'a'] { 11 | flag = true 12 | break 13 | } 14 | } 15 | if !flag { 16 | count++ 17 | } 18 | } 19 | return count 20 | } -------------------------------------------------------------------------------- /175-combine-two-tables/combine-two-tables.sql: -------------------------------------------------------------------------------- 1 | -- Write your PostgreSQL query statement below 2 | SELECT firstName, lastName, city, state 3 | FROM Person 4 | LEFT JOIN Address ON Person.personId = Address.personId; -------------------------------------------------------------------------------- /2235-add-two-integers/README.md: -------------------------------------------------------------------------------- 1 |

Add Two Integers

Difficulty: Easy
Given two integers num1 and num2, return the sum of the two integers. 2 |

 

3 |

Example 1:

4 | 5 |
 6 | Input: num1 = 12, num2 = 5
 7 | Output: 17
 8 | Explanation: num1 is 12, num2 is 5, and their sum is 12 + 5 = 17, so 17 is returned.
 9 | 
10 | 11 |

Example 2:

12 | 13 |
14 | Input: num1 = -10, num2 = 4
15 | Output: -6
16 | Explanation: num1 + num2 = -6, so -6 is returned.
17 | 
18 | 19 |

 

20 |

Constraints:

21 | 22 | 25 | -------------------------------------------------------------------------------- /2235-add-two-integers/add-two-integers.go: -------------------------------------------------------------------------------- 1 | func sum(num1 int, num2 int) int { 2 | return num1 + num2 3 | } -------------------------------------------------------------------------------- /2248-intersection-of-multiple-arrays/intersection-of-multiple-arrays.go: -------------------------------------------------------------------------------- 1 | func intersection(nums [][]int) []int { 2 | numsArr := make([]int, 1001) 3 | output := make([]int, 0, len(nums[0])) 4 | for _, arr := range nums { 5 | for _, num := range arr { 6 | numsArr[num]++ 7 | } 8 | } 9 | for i := 1; i < 1001; i++ { 10 | if numsArr[i] == len(nums) { 11 | output = append(output, i) 12 | } 13 | } 14 | return output 15 | } -------------------------------------------------------------------------------- /2278-percentage-of-letter-in-string/percentage-of-letter-in-string.go: -------------------------------------------------------------------------------- 1 | func percentageLetter(s string, letter byte) int { 2 | count := 0; 3 | for i := 0; i < len(s); i++ { 4 | if s[i] == letter { 5 | count++ 6 | } 7 | } 8 | // fmt.Println("COUNT : ", count, "LENGTH : ", len(s)) 9 | return (count * 100) / len(s) 10 | } -------------------------------------------------------------------------------- /228-summary-ranges/summary-ranges.go: -------------------------------------------------------------------------------- 1 | func summaryRanges(nums []int) []string { 2 | var output []string 3 | for i := 0; i < len(nums); i++ { 4 | j := i 5 | for (j + 1 < len(nums) && nums[j+1] == nums[j] + 1) { 6 | j++ 7 | } 8 | if i == j { 9 | output = append(output, fmt.Sprintf("%v", nums[i])) 10 | } else { 11 | output = append(output, fmt.Sprintf("%d->%d", nums[i], nums[j])) 12 | } 13 | i = j 14 | } 15 | return output 16 | } -------------------------------------------------------------------------------- /2413-smallest-even-multiple/README.md: -------------------------------------------------------------------------------- 1 |

Smallest Even Multiple

Difficulty: Easy
Given a positive integer n, return the smallest positive integer that is a multiple of both 2 and n. 2 |

 

3 |

Example 1:

4 | 5 |
 6 | Input: n = 5
 7 | Output: 10
 8 | Explanation: The smallest multiple of both 5 and 2 is 10.
 9 | 
10 | 11 |

Example 2:

12 | 13 |
14 | Input: n = 6
15 | Output: 6
16 | Explanation: The smallest multiple of both 6 and 2 is 6. Note that a number is a multiple of itself.
17 | 
18 | 19 |

 

20 |

Constraints:

21 | 22 | 25 | -------------------------------------------------------------------------------- /2413-smallest-even-multiple/smallest-even-multiple.go: -------------------------------------------------------------------------------- 1 | func smallestEvenMultiple(n int) int { 2 | if n % 2 == 0 { 3 | return n 4 | } 5 | return n * 2 6 | } -------------------------------------------------------------------------------- /2469-convert-the-temperature/convert-the-temperature.go: -------------------------------------------------------------------------------- 1 | func convertTemperature(celsius float64) []float64 { 2 | kelvin := celsius + 273.15 3 | fahrenheit := celsius * 1.80 + 32.00 4 | arr := []float64{kelvin,fahrenheit} 5 | return arr 6 | } -------------------------------------------------------------------------------- /2894-divisible-and-non-divisible-sums-difference/divisible-and-non-divisible-sums-difference.go: -------------------------------------------------------------------------------- 1 | func differenceOfSums(n int, m int) int { 2 | num1, num2 := 0, 0 3 | for i := 1; i <= n; i++ { 4 | if i % m == 0 { 5 | num2 += i 6 | } else { 7 | num1 += i 8 | } 9 | } 10 | return num1 - num2 11 | } -------------------------------------------------------------------------------- /3028-ant-on-the-boundary/ant-on-the-boundary.go: -------------------------------------------------------------------------------- 1 | func returnToBoundaryCount(nums []int) int { 2 | pos, count := 0, 0 3 | for _, num := range nums { 4 | pos += num 5 | if pos == 0 { 6 | count++ 7 | } 8 | } 9 | 10 | return count 11 | } -------------------------------------------------------------------------------- /3079-find-the-sum-of-encrypted-integers/find-the-sum-of-encrypted-integers.go: -------------------------------------------------------------------------------- 1 | func sumOfEncryptedInt(nums []int) int { 2 | sum := 0 3 | for _, num := range nums { 4 | sum += encrypt(num) 5 | } 6 | return sum 7 | } 8 | func encrypt(num int) int { 9 | count, large := 0, 0 10 | for num > 0 { 11 | if num % 10 > large { 12 | large = num % 10 13 | } 14 | num /= 10 15 | count++ 16 | } 17 | for i:=1; i 0 { 4 | val := temp % 10 5 | sum += val 6 | temp /= 10 7 | } 8 | min := sum 9 | for _, num := range nums { 10 | temp, sum = num, 0 11 | for temp > 0 { 12 | val := temp % 10 13 | sum += val 14 | temp /= 10 15 | } 16 | if min > sum { 17 | min = sum 18 | } 19 | } 20 | return min 21 | } -------------------------------------------------------------------------------- /3340-check-balanced-string/check-balanced-string.go: -------------------------------------------------------------------------------- 1 | func isBalanced(num string) bool { 2 | var odd byte 3 | var even byte 4 | for i := 0; i < len(num); i++ { 5 | if i % 2 == 0 { 6 | even += num[i] - '0' 7 | } else { 8 | odd += num[i] - '0' 9 | } 10 | } 11 | // fmt.Println("odd : ",odd,"\teven : ",even) 12 | if odd == even { 13 | return true 14 | } 15 | return false 16 | } -------------------------------------------------------------------------------- /3345-smallest-divisible-digit-product-i/smallest-divisible-digit-product-i.go: -------------------------------------------------------------------------------- 1 | func smallestNumber(n int, t int) int { 2 | for { 3 | prod := 1 4 | for temp := n; temp > 0; temp /= 10 { 5 | prod *= temp % 10 6 | } 7 | if prod % t == 0 { 8 | return n 9 | } else { 10 | n++ 11 | } 12 | } 13 | return 0 14 | } -------------------------------------------------------------------------------- /3370-smallest-number-with-all-set-bits/smallest-number-with-all-set-bits.go: -------------------------------------------------------------------------------- 1 | func smallestNumber(n int) int { 2 | x := n 3 | for { 4 | if x % 2 == 0 { 5 | x++ 6 | continue 7 | } 8 | temp := x 9 | flag := false 10 | for temp > 0 { 11 | if temp % 2 == 0 { 12 | flag = true 13 | break 14 | } 15 | temp /= 2 16 | } 17 | if flag == false { 18 | return x 19 | } 20 | x++ 21 | } 22 | return n 23 | } -------------------------------------------------------------------------------- /412-fizz-buzz/fizz-buzz.go: -------------------------------------------------------------------------------- 1 | func fizzBuzz(n int) []string { 2 | output := make([]string, n) 3 | for i := 1; i <= n; i++ { 4 | if i % 3 == 0 && i % 5 == 0 { 5 | output[i-1] = "FizzBuzz" 6 | } else if i % 3 == 0 { 7 | output[i-1] = "Fizz" 8 | } else if i % 5 == 0 { 9 | output[i-1] = "Buzz" 10 | } else { 11 | output[i-1] = strconv.Itoa(i) 12 | } 13 | } 14 | return output 15 | } -------------------------------------------------------------------------------- /58-length-of-last-word/length-of-last-word.go: -------------------------------------------------------------------------------- 1 | func lengthOfLastWord(s string) int { 2 | current, lastLength := 0, 0 3 | for _, char := range s { 4 | if char != ' ' { 5 | current++ 6 | } else { 7 | current = 0 8 | } 9 | if current > 0 { 10 | lastLength = current 11 | } 12 | } 13 | return lastLength 14 | } -------------------------------------------------------------------------------- /88-merge-sorted-array/merge-sorted-array.go: -------------------------------------------------------------------------------- 1 | func merge(nums1 []int, m int, nums2 []int, n int) { 2 | // if m == 0 { 3 | // nums1 = nums2 4 | // } else if n == 0 { 5 | // return 6 | // } 7 | l := m + n - 1 8 | for n > 0 { 9 | if m > 0 && (nums1[m-1] >= nums2[n-1]) { 10 | nums1[l] = nums1[m-1] 11 | m-- 12 | l-- 13 | } else { 14 | nums1[l] = nums2[n-1] 15 | n-- 16 | l-- 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /C/Leetcode 1185 Day of the Week.c: -------------------------------------------------------------------------------- 1 | //Leetcode 1185 Day of the Week 2 | char * dayOfTheWeek(int day, int month, int year){ 3 | if(month<3){ 4 | month += 12; 5 | year--; 6 | } 7 | int year_of_century = year % 100; 8 | int century = year / 100; 9 | int decade = month; 10 | int weekday = ( (day + (13 * (decade + 1) / 5) + year_of_century + (year_of_century / 4) + (century / 4) - (2 * century)) % 7); 11 | char *days[] = {"Saturday","Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"}; 12 | return days[(weekday+7)%7]; 13 | } 14 | -------------------------------------------------------------------------------- /C/Leetcode 283 Move Zeroes.c: -------------------------------------------------------------------------------- 1 | //Leetcode 283 Move Zeroes 2 | void moveZeroes(int* nums, int numsSize){ 3 | int i,j=0; 4 | for(i=0;iBalanced Binary Tree Difficulty: Easy

Given a binary tree, determine if it is height-balanced.

2 | 3 |

 

4 |

Example 1:

5 | 6 |
 7 | Input: root = [3,9,20,null,null,15,7]
 8 | Output: true
 9 | 
10 | 11 |

Example 2:

12 | 13 |
14 | Input: root = [1,2,2,3,3,null,null,4,4]
15 | Output: false
16 | 
17 | 18 |

Example 3:

19 | 20 |
21 | Input: root = []
22 | Output: true
23 | 
24 | 25 |

 

26 |

Constraints:

27 | 28 | 32 | -------------------------------------------------------------------------------- /Golang/110-balanced-binary-tree/balanced-binary-tree.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * type TreeNode struct { 4 | * Val int 5 | * Left *TreeNode 6 | * Right *TreeNode 7 | * } 8 | */ 9 | func isBalanced(root *TreeNode) bool { 10 | if root == nil { 11 | return true 12 | } 13 | // left := height(root.Left) 14 | // right := height(root.Right) 15 | if abs(height(root.Left), height(root.Right)) > 1 { 16 | return false 17 | } 18 | return isBalanced(root.Left) && isBalanced(root.Right) 19 | } 20 | func height(root *TreeNode) int { 21 | if root == nil { 22 | return 0 23 | } 24 | return max(height(root.Left), height(root.Right)) + 1 25 | } 26 | func abs(x, y int) int { 27 | if x >= y { 28 | return x - y 29 | } 30 | return y - x 31 | } 32 | func max(x, y int) int { 33 | if x >= y { 34 | return x 35 | } 36 | return y 37 | } -------------------------------------------------------------------------------- /Golang/1137-height-checker/height-checker.go: -------------------------------------------------------------------------------- 1 | func heightChecker(heights []int) int { 2 | temp := make([]int, 0, len(heights)) 3 | temp = append(temp, heights...) 4 | count := 0 5 | slices.Sort(temp) 6 | for i := 0; i < len(heights); i++ { 7 | if heights[i] != temp[i] { 8 | count++ 9 | } 10 | } 11 | return count 12 | } -------------------------------------------------------------------------------- /Golang/1146-greatest-common-divisor-of-strings/greatest-common-divisor-of-strings.go: -------------------------------------------------------------------------------- 1 | func gcdOfStrings(str1 string, str2 string) string { 2 | if str1 + str2 != str2 + str1 { 3 | return "" 4 | } 5 | if str1 == str2 { 6 | return str1 7 | } 8 | val := gcd(len(str1), len(str2)) 9 | return str1[:val] 10 | } 11 | func gcd(a, b int) int { 12 | for b != 0 { 13 | a, b = b, a % b 14 | } 15 | return a 16 | 17 | } -------------------------------------------------------------------------------- /Golang/118-pascals-triangle/README.md: -------------------------------------------------------------------------------- 1 |

Pascal's Triangle

Difficulty: Easy

Given an integer numRows, return the first numRows of Pascal's triangle.

2 | 3 |

In Pascal's triangle, each number is the sum of the two numbers directly above it as shown:

4 | 5 |

 

6 |

Example 1:

7 |
Input: numRows = 5
 8 | Output: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]
 9 | 

Example 2:

10 |
Input: numRows = 1
11 | Output: [[1]]
12 | 
13 |

 

14 |

Constraints:

15 | 16 | 19 | -------------------------------------------------------------------------------- /Golang/118-pascals-triangle/pascals-triangle.go: -------------------------------------------------------------------------------- 1 | func generate(numRows int) [][]int { 2 | output := make([][]int, 0, numRows) 3 | output = append(output, []int{1}) 4 | // fmt.Println(output) 5 | for i := 1; i < numRows; i++ { 6 | newRow := make([]int, 0, i+1) 7 | newRow = append(newRow, 1) 8 | for j := 1; j < i; j++ { 9 | newRow = append(newRow, output[i-1][j-1]+output[i-1][j]) 10 | } 11 | newRow = append(newRow, 1) 12 | output = append(output, newRow) 13 | } 14 | // fmt.Println(output) 15 | return output 16 | } -------------------------------------------------------------------------------- /Golang/119-pascals-triangle-ii/README.md: -------------------------------------------------------------------------------- 1 |

Pascal's Triangle II

Difficulty: Easy

Given an integer rowIndex, return the rowIndexth (0-indexed) row of the Pascal's triangle.

2 | 3 |

In Pascal's triangle, each number is the sum of the two numbers directly above it as shown:

4 | 5 |

 

6 |

Example 1:

7 |
Input: rowIndex = 3
 8 | Output: [1,3,3,1]
 9 | 

Example 2:

10 |
Input: rowIndex = 0
11 | Output: [1]
12 | 

Example 3:

13 |
Input: rowIndex = 1
14 | Output: [1,1]
15 | 
16 |

 

17 |

Constraints:

18 | 19 | 22 | 23 |

 

24 |

Follow up: Could you optimize your algorithm to use only O(rowIndex) extra space?

25 | -------------------------------------------------------------------------------- /Golang/119-pascals-triangle-ii/pascals-triangle-ii.go: -------------------------------------------------------------------------------- 1 | func getRow(rowIndex int) []int { 2 | if rowIndex == 0 { 3 | return []int{1} 4 | } 5 | output := make([][]int, 0, rowIndex+1) 6 | output = append(output, []int{1}) 7 | for i := 1; i <= rowIndex; i++ { 8 | newRow := make([]int, 0, i+1) 9 | newRow = append(newRow, 1) 10 | for j := 1; j < i; j++ { 11 | newRow = append(newRow, output[i-1][j-1]+output[i-1][j]) 12 | } 13 | newRow = append(newRow, 1) 14 | output = append(output, newRow) 15 | } 16 | return output[rowIndex] 17 | } -------------------------------------------------------------------------------- /Golang/1217-relative-sort-array/relative-sort-array.go: -------------------------------------------------------------------------------- 1 | func relativeSortArray(arr1 []int, arr2 []int) []int { 2 | idxArr1, idxArr2 := make([]int, 1001), make([]bool, 1001) 3 | size1, size2 := len(arr1), len(arr2) 4 | output := make([]int, 0, (size1 + size2)) 5 | for _, num := range arr1 { 6 | idxArr1[num]++ 7 | } 8 | for _, num := range arr2 { 9 | idxArr2[num] = true 10 | } 11 | for _, num := range arr2 { 12 | output = append(output, num) 13 | for idxArr1[num] > 1 { 14 | output = append(output, num) 15 | idxArr1[num]-- 16 | } 17 | idxArr1[num]-- 18 | } 19 | for idx, num := range idxArr1 { 20 | for i := 1; i <= num; i++ { 21 | output = append(output, idx) 22 | } 23 | } 24 | return output 25 | } -------------------------------------------------------------------------------- /Golang/1231-replace-elements-with-greatest-element-on-right-side/replace-elements-with-greatest-element-on-right-side.go: -------------------------------------------------------------------------------- 1 | func replaceElements(arr []int) []int { 2 | for i, max := len(arr)-1, -1; i >= 0; i-- { 3 | if arr[i] > max { 4 | arr[i], max = max, arr[i] 5 | } else { 6 | arr[i] = max 7 | } 8 | } 9 | return arr 10 | } -------------------------------------------------------------------------------- /Golang/1236-n-th-tribonacci-number/README.md: -------------------------------------------------------------------------------- 1 |

N-th Tribonacci Number

Difficulty: Easy

The Tribonacci sequence Tn is defined as follows: 

2 | 3 |

T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0.

4 | 5 |

Given n, return the value of Tn.

6 | 7 |

 

8 |

Example 1:

9 | 10 |
11 | Input: n = 4
12 | Output: 4
13 | Explanation:
14 | T_3 = 0 + 1 + 1 = 2
15 | T_4 = 1 + 1 + 2 = 4
16 | 
17 | 18 |

Example 2:

19 | 20 |
21 | Input: n = 25
22 | Output: 1389537
23 | 
24 | 25 |

 

26 |

Constraints:

27 | 28 | -------------------------------------------------------------------------------- /Golang/1236-n-th-tribonacci-number/n-th-tribonacci-number.go: -------------------------------------------------------------------------------- 1 | func tribonacci(n int) int { 2 | if n == 0 { 3 | return 0 4 | } else if n < 3 { 5 | return 1 6 | } 7 | arr := [38]int{0,1,1,2,4} 8 | for i := 3; i <= n; i++ { 9 | arr[i] = arr[i-1] + arr[i-2] + arr[i-3] 10 | } 11 | return arr[n] 12 | } -------------------------------------------------------------------------------- /Golang/125-valid-palindrome/valid-palindrome.go: -------------------------------------------------------------------------------- 1 | func isPalindrome(s string) bool { 2 | size := len(s) 3 | str := make([]byte, 0, size) 4 | for i := 0; i < size; i++ { 5 | if s[i] >= 'a' && s[i] <= 'z' { 6 | str = append(str, s[i]) 7 | } else if s[i] >= 'A' && s[i] <= 'Z' { 8 | str = append(str, byte(s[i] + 32)) 9 | } else if s[i] >= '0' && s[i] <= '9' { 10 | str = append(str, s[i]) 11 | } 12 | } 13 | if len(str) == 0 { 14 | return true 15 | } 16 | for i := 0; i < len(str)/2; i++ { 17 | if str[i] != str[len(str)-i-1] { 18 | return false 19 | } 20 | } 21 | return true 22 | } -------------------------------------------------------------------------------- /Golang/1421-find-numbers-with-even-number-of-digits/find-numbers-with-even-number-of-digits.go: -------------------------------------------------------------------------------- 1 | func findNumbers(nums []int) int { 2 | evenDigits := 0 3 | for _, num := range nums { 4 | if evenLength(num) { 5 | evenDigits++ 6 | } 7 | } 8 | return evenDigits 9 | } 10 | func evenLength(num int) bool { 11 | length := 0 12 | for num > 0 { 13 | num /= 10 14 | length++ 15 | } 16 | if length % 2 == 0 { 17 | return true 18 | } 19 | return false 20 | } -------------------------------------------------------------------------------- /Golang/145-binary-tree-postorder-traversal/README.md: -------------------------------------------------------------------------------- 1 |

Binary Tree Postorder Traversal

Difficulty: Easy

Given the root of a binary tree, return the postorder traversal of its nodes' values.

2 | 3 |

 

4 |

Example 1:

5 | 6 |
 7 | Input: root = [1,null,2,3]
 8 | Output: [3,2,1]
 9 | 
10 | 11 |

Example 2:

12 | 13 |
14 | Input: root = []
15 | Output: []
16 | 
17 | 18 |

Example 3:

19 | 20 |
21 | Input: root = [1]
22 | Output: [1]
23 | 
24 | 25 |

 

26 |

Constraints:

27 | 28 | 32 | 33 |

 

34 | Follow up: Recursive solution is trivial, could you do it iteratively? -------------------------------------------------------------------------------- /Golang/145-binary-tree-postorder-traversal/binary-tree-postorder-traversal.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * type TreeNode struct { 4 | * Val int 5 | * Left *TreeNode 6 | * Right *TreeNode 7 | * } 8 | */ 9 | func postorderTraversal(root *TreeNode) []int { 10 | nums := []int{} 11 | if root == nil { 12 | return nums 13 | } 14 | nums = append(nums, postorderTraversal(root.Left)...) 15 | nums = append(nums, postorderTraversal(root.Right)...) 16 | nums = append(nums, root.Val) 17 | return nums 18 | } -------------------------------------------------------------------------------- /Golang/1462-list-the-products-ordered-in-a-period/list-the-products-ordered-in-a-period.sql: -------------------------------------------------------------------------------- 1 | SELECT p.product_name, SUM(o.unit) AS unit 2 | FROM products AS p 3 | JOIN orders AS o 4 | ON p.product_id = o.product_id 5 | WHERE o.order_date >= '2020-02-01' AND o.order_date <= '2020-02-29' 6 | GROUP BY p.product_name 7 | HAVING SUM(o.unit) > 99; -------------------------------------------------------------------------------- /Golang/1496-lucky-numbers-in-a-matrix/lucky-numbers-in-a-matrix.go: -------------------------------------------------------------------------------- 1 | func luckyNumbers (matrix [][]int) []int { 2 | output := make([]int, 0) 3 | minSet := make(map[int]bool) 4 | m, n := len(matrix), len(matrix[0]) 5 | for i := 0; i < m; i++ { 6 | min := matrix[i][0] 7 | for j := 1; j < n; j++ { 8 | if matrix[i][j] < min { 9 | min = matrix[i][j] 10 | } 11 | } 12 | minSet[min] = true 13 | } 14 | for i := 0; i < n; i++ { 15 | max := matrix[0][i] 16 | for j := 1; j < m; j++ { 17 | if matrix[j][i] > max { 18 | max = matrix[j][i] 19 | } 20 | } 21 | if _, exists := minSet[max]; exists { 22 | output = append(output, max) 23 | } 24 | } 25 | return output 26 | } -------------------------------------------------------------------------------- /Golang/1542-consecutive-characters/README.md: -------------------------------------------------------------------------------- 1 |

Consecutive Characters

Difficulty: Easy

The power of the string is the maximum length of a non-empty substring that contains only one unique character.

2 | 3 |

Given a string s, return the power of s.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
 9 | Input: s = "leetcode"
10 | Output: 2
11 | Explanation: The substring "ee" is of length 2 with the character 'e' only.
12 | 
13 | 14 |

Example 2:

15 | 16 |
17 | Input: s = "abbcccddddeeeeedcba"
18 | Output: 5
19 | Explanation: The substring "eeeee" is of length 5 with the character 'e' only.
20 | 
21 | 22 |

 

23 |

Constraints:

24 | 25 | 29 | -------------------------------------------------------------------------------- /Golang/1542-consecutive-characters/consecutive-characters.go: -------------------------------------------------------------------------------- 1 | func maxPower(s string) int { 2 | count, maxCount := 1, 1 3 | for i := 0; i < len(s)-1; i++ { 4 | if s[i] == s[i+1] { 5 | count++ 6 | } else { 7 | if count > maxCount { 8 | maxCount = count 9 | } 10 | count = 1 11 | } 12 | } 13 | if count > maxCount { 14 | maxCount = count 15 | } 16 | return maxCount 17 | } -------------------------------------------------------------------------------- /Golang/1547-destination-city/destination-city.go: -------------------------------------------------------------------------------- 1 | func destCity(paths [][]string) string { 2 | destMap := make(map[string]string) 3 | for _, val := range paths { 4 | destMap[val[0]] = val[1] 5 | } 6 | // fmt.Println(destMap) 7 | // init := paths[0][0] 8 | // fmt.Println(init) 9 | for _, val := range destMap { 10 | if _, exists := destMap[val]; !exists { 11 | return val 12 | } 13 | // init = destMap[init] 14 | // fmt.Println(init) 15 | } 16 | return "" 17 | } -------------------------------------------------------------------------------- /Golang/1614-maximum-nesting-depth-of-the-parentheses/maximum-nesting-depth-of-the-parentheses.go: -------------------------------------------------------------------------------- 1 | func maxDepth(s string) int { 2 | max, depth := 0, 0 3 | for _, ch := range s { 4 | if ch == '(' { 5 | depth++ 6 | if depth > max { 7 | max = depth 8 | } 9 | } else if ch == ')' { 10 | depth-- 11 | } 12 | } 13 | return max 14 | } -------------------------------------------------------------------------------- /Golang/1656-count-good-triplets/count-good-triplets.go: -------------------------------------------------------------------------------- 1 | func countGoodTriplets(arr []int, a int, b int, c int) int { 2 | size, count := len(arr), 0 3 | for i := 0; i < size; i++ { 4 | for j := i+1; j < size; j++ { 5 | for k := j + 1; k < size; k++ { 6 | if abs(arr[i] - arr[j]) <= a && abs(arr[j] - arr[k]) <= b && abs(arr[i] - arr[k]) <= c { 7 | count++ 8 | } 9 | } 10 | } 11 | } 12 | return count 13 | } 14 | func abs(num int) int { 15 | if num >= 0{ 16 | return num 17 | } 18 | return -num 19 | } -------------------------------------------------------------------------------- /Golang/167-two-sum-ii-input-array-is-sorted/two-sum-ii-input-array-is-sorted.go: -------------------------------------------------------------------------------- 1 | func twoSum(numbers []int, target int) []int { 2 | output := []int{0, 0} 3 | size := len(numbers) 4 | numsMap := make(map[int]int, size) 5 | for idx, num := range numbers { 6 | if _, err := numsMap[target - num]; err { 7 | return []int{numsMap[target - num]+1, idx+1} 8 | } 9 | numsMap[num] = idx 10 | } 11 | return output 12 | } -------------------------------------------------------------------------------- /Golang/169-majority-element/README.md: -------------------------------------------------------------------------------- 1 |

Majority Element

Difficulty: Easy

Given an array nums of size n, return the majority element.

2 | 3 |

The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array.

4 | 5 |

 

6 |

Example 1:

7 |
Input: nums = [3,2,3]
 8 | Output: 3
 9 | 

Example 2:

10 |
Input: nums = [2,2,1,1,1,2,2]
11 | Output: 2
12 | 
13 |

 

14 |

Constraints:

15 | 16 | 21 | 22 |

 

23 | Follow-up: Could you solve the problem in linear time and in O(1) space? -------------------------------------------------------------------------------- /Golang/169-majority-element/majority-element.go: -------------------------------------------------------------------------------- 1 | func majorityElement(nums []int) int { 2 | numMap := make(map[int]int) 3 | for _, num := range nums { 4 | numMap[num]++ 5 | } 6 | large := 1 7 | num := nums[0] 8 | for index, value := range numMap { 9 | if value > large { 10 | large = value 11 | num = index 12 | } 13 | } 14 | return num 15 | } -------------------------------------------------------------------------------- /Golang/1786-count-the-number-of-consistent-strings/count-the-number-of-consistent-strings.go: -------------------------------------------------------------------------------- 1 | func countConsistentStrings(allowed string, words []string) int { 2 | allowedArr := make([]bool, 26) 3 | var count int 4 | for _, char := range allowed { 5 | allowedArr[char - 'a'] = true 6 | } 7 | for _, word := range words { 8 | var flag bool 9 | for _, char := range word { 10 | if !allowedArr[char - 'a'] { 11 | flag = true 12 | break 13 | } 14 | } 15 | if !flag { 16 | count++ 17 | } 18 | } 19 | return count 20 | } -------------------------------------------------------------------------------- /Golang/189-rotate-array/rotate-array.go: -------------------------------------------------------------------------------- 1 | func rotate(nums []int, k int) { 2 | size := len(nums) 3 | k = k % size 4 | for i := 0; i < size / 2; i++ { 5 | nums[i], nums[size-i-1] = nums[size-i-1], nums[i] 6 | } 7 | // fmt.Println("Reverse : ", nums) 8 | for i := 0; i < k/2; i++ { 9 | nums[i], nums[k-i-1] = nums[k-i-1], nums[i] 10 | } 11 | // fmt.Println("first : ", nums) 12 | for i, j := k, 1; i < (size + k) / 2; i++ { 13 | nums[i], nums[size-j] = nums[size-j], nums[i] 14 | j++ 15 | } 16 | // fmt.Println("second : ", nums) 17 | } -------------------------------------------------------------------------------- /Golang/1894-merge-strings-alternately/merge-strings-alternately.go: -------------------------------------------------------------------------------- 1 | func mergeAlternately(word1 string, word2 string) string { 2 | l1, l2 := len(word1), len(word2) 3 | result := make([]byte, 0, (l1+l2)) 4 | for i, j := 0, 0; i < l1 || j < l2; { 5 | if i < l1 { 6 | result = append(result, word1[i]) 7 | i++ 8 | } 9 | if j < l2 { 10 | result = append(result, word2[j]) 11 | j++ 12 | } 13 | } 14 | return string(result) 15 | } -------------------------------------------------------------------------------- /Golang/1952-three-divisors/README.md: -------------------------------------------------------------------------------- 1 |

Three Divisors

Difficulty: Easy

Given an integer n, return true if n has exactly three positive divisors. Otherwise, return false.

2 | 3 |

An integer m is a divisor of n if there exists an integer k such that n = k * m.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
 9 | Input: n = 2
10 | Output: false
11 | Explantion: 2 has only two divisors: 1 and 2.
12 | 
13 | 14 |

Example 2:

15 | 16 |
17 | Input: n = 4
18 | Output: true
19 | Explantion: 4 has three divisors: 1, 2, and 4.
20 | 
21 | 22 |

 

23 |

Constraints:

24 | 25 | 28 | -------------------------------------------------------------------------------- /Golang/1952-three-divisors/three-divisors.go: -------------------------------------------------------------------------------- 1 | func isThree(n int) bool { 2 | count := 0 3 | for i := 1; i <= n; i++ { 4 | if n % i == 0 { 5 | count++ 6 | } 7 | if count > 3 { 8 | return false 9 | } 10 | } 11 | if count == 3 { 12 | return true 13 | } 14 | return false 15 | } -------------------------------------------------------------------------------- /Golang/1987-substrings-of-size-three-with-distinct-characters/substrings-of-size-three-with-distinct-characters.go: -------------------------------------------------------------------------------- 1 | func countGoodSubstrings(s string) int { 2 | count := 0 3 | if len(s) < 3 { 4 | return 0 5 | } 6 | stringSet := make(map[byte]int) 7 | for i := 0; i < 3; i++ { 8 | stringSet[s[i]]++ 9 | } 10 | if len(stringSet) == 3 { 11 | count++ 12 | } 13 | for i := 3; i < len(s); i++ { 14 | if stringSet[s[i-3]] == 1 { 15 | delete(stringSet, s[i-3]) 16 | } else { 17 | stringSet[s[i-3]]-- 18 | } 19 | stringSet[s[i]]++ 20 | if len(stringSet) == 3 { 21 | count++ 22 | } 23 | } 24 | return count 25 | } -------------------------------------------------------------------------------- /Golang/2010-check-if-word-equals-summation-of-two-words/check-if-word-equals-summation-of-two-words.go: -------------------------------------------------------------------------------- 1 | func isSumEqual(firstWord string, secondWord string, targetWord string) bool { 2 | word1, word2, targetSum := 0, 0, 0 3 | for _, char := range firstWord { 4 | word1 = word1 * 10 + int(char - 'a') 5 | } 6 | for _, char := range secondWord { 7 | word2 = word2 * 10 + int(char - 'a') 8 | } 9 | for _, char := range targetWord { 10 | targetSum = targetSum * 10 + int(char - 'a') 11 | } 12 | // fmt.Println(word2, targetSum) 13 | if word1 + word2 == targetSum { 14 | return true 15 | } 16 | return false 17 | } -------------------------------------------------------------------------------- /Golang/2032-largest-odd-number-in-string/largest-odd-number-in-string.go: -------------------------------------------------------------------------------- 1 | func largestOddNumber(num string) string { 2 | size := len(num) 3 | 4 | for i := size - 1; i >= 0; i-- { 5 | if int(num[i]) % 2 == 1 { 6 | return num[:i+1] 7 | } 8 | } 9 | 10 | return "" 11 | } -------------------------------------------------------------------------------- /Golang/2037-count-square-sum-triples/README.md: -------------------------------------------------------------------------------- 1 |

Count Square Sum Triples

Difficulty: Easy

A square triple (a,b,c) is a triple where a, b, and c are integers and a2 + b2 = c2.

2 | 3 |

Given an integer n, return the number of square triples such that 1 <= a, b, c <= n.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
 9 | Input: n = 5
10 | Output: 2
11 | Explanation: The square triples are (3,4,5) and (4,3,5).
12 | 
13 | 14 |

Example 2:

15 | 16 |
17 | Input: n = 10
18 | Output: 4
19 | Explanation: The square triples are (3,4,5), (4,3,5), (6,8,10), and (8,6,10).
20 | 
21 | 22 |

 

23 |

Constraints:

24 | 25 | 28 | -------------------------------------------------------------------------------- /Golang/2037-count-square-sum-triples/count-square-sum-triples.go: -------------------------------------------------------------------------------- 1 | func countTriples(n int) int { 2 | count := 0 3 | for i := 1; i <= n; i++ { 4 | for j := 1; j <= n; j++ { 5 | k := int(math.Sqrt(float64(i*i + j*j))) 6 | if k <= n && k * k == i * i + j * j { 7 | count++ 8 | } 9 | } 10 | } 11 | return count 12 | } -------------------------------------------------------------------------------- /Golang/2053-check-if-all-characters-have-equal-number-of-occurrences/check-if-all-characters-have-equal-number-of-occurrences.go: -------------------------------------------------------------------------------- 1 | func areOccurrencesEqual(s string) bool { 2 | charArr := [26]int{} 3 | value := 0 4 | for _, char := range s { 5 | charArr[char - 'a']++ 6 | value = charArr[char - 'a'] 7 | } 8 | for _, val := range charArr { 9 | if val != 0 && val != value { 10 | return false 11 | } 12 | } 13 | return true 14 | } -------------------------------------------------------------------------------- /Golang/206-reverse-linked-list/reverse-linked-list.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * type ListNode struct { 4 | * Val int 5 | * Next *ListNode 6 | * } 7 | */ 8 | func reverseList(head *ListNode) *ListNode { 9 | if head == nil || head.Next == nil { 10 | return head 11 | } 12 | var revHead *ListNode 13 | for head != nil { 14 | tmp := head.Next 15 | head.Next = revHead 16 | revHead = head 17 | head = tmp 18 | } 19 | return revHead 20 | } -------------------------------------------------------------------------------- /Golang/2132-convert-1d-array-into-2d-array/convert-1d-array-into-2d-array.go: -------------------------------------------------------------------------------- 1 | func construct2DArray(original []int, m int, n int) [][]int { 2 | if n * m != len(original) { 3 | return [][]int{} 4 | } 5 | 6 | output := make([][]int, m) 7 | 8 | for i, idx := 0, 0; i < m; i++ { 9 | output[i] = make([]int, n) 10 | for j := 0; j < n; j++ { 11 | output[i][j] = original[idx] 12 | idx++ 13 | } 14 | } 15 | 16 | return output 17 | } -------------------------------------------------------------------------------- /Golang/2148-minimum-number-of-moves-to-seat-everyone/minimum-number-of-moves-to-seat-everyone.go: -------------------------------------------------------------------------------- 1 | func minMovesToSeat(seats []int, students []int) int { 2 | moves := 0 3 | sort.Ints(seats) 4 | sort.Ints(students) 5 | fmt.Println(seats) 6 | fmt.Println(students) 7 | for i := 0; i < len(seats); i++ { 8 | moves += abs(seats[i] - students[i]) 9 | } 10 | return moves 11 | } 12 | func abs(num int) int { 13 | if num >= 0 { 14 | return num 15 | } 16 | return -num 17 | } -------------------------------------------------------------------------------- /Golang/2181-smallest-index-with-equal-value/smallest-index-with-equal-value.go: -------------------------------------------------------------------------------- 1 | func smallestEqual(nums []int) int { 2 | for i, v := range nums { 3 | if i % 10 == v { 4 | return i 5 | } 6 | } 7 | 8 | return -1 9 | } -------------------------------------------------------------------------------- /Golang/2219-maximum-number-of-words-found-in-sentences/maximum-number-of-words-found-in-sentences.go: -------------------------------------------------------------------------------- 1 | func mostWordsFound(sentences []string) int { 2 | maxCount := 0 3 | for i := 0; i < len(sentences); i++ { 4 | count := 1 5 | for j := 0; j < len(sentences[i]); j++ { 6 | if sentences[i][j] == ' ' { 7 | count += 1 8 | } 9 | } 10 | if count > maxCount { 11 | maxCount = count 12 | } 13 | } 14 | return maxCount 15 | } -------------------------------------------------------------------------------- /Golang/2269-count-elements-with-strictly-smaller-and-greater-elements/count-elements-with-strictly-smaller-and-greater-elements.go: -------------------------------------------------------------------------------- 1 | func countElements(nums []int) int { 2 | max, min := -100001, 100001 3 | count := 0 4 | for i := 0; i < len(nums); i++ { 5 | if nums[i] > max { 6 | max = nums[i] 7 | } 8 | if nums[i] < min { 9 | min = nums[i] 10 | } 11 | } 12 | fmt.Println("max : ", max, "\tmin : ", min) 13 | for i := 0; i < len(nums); i++ { 14 | if nums[i] > min && nums[i] < max{ 15 | count++ 16 | } 17 | } 18 | return count 19 | } -------------------------------------------------------------------------------- /Golang/2271-rearrange-array-elements-by-sign/rearrange-array-elements-by-sign.go: -------------------------------------------------------------------------------- 1 | func rearrangeArray(nums []int) []int { 2 | size := len(nums) 3 | result := make([]int, size, size) 4 | for i, pos, neg := 0, 0, 1; i < size; i++ { 5 | if nums[i] < 0 { 6 | result[neg] = nums[i] 7 | neg += 2 8 | } else { 9 | result[pos] = nums[i] 10 | pos += 2 11 | } 12 | } 13 | return result 14 | } -------------------------------------------------------------------------------- /Golang/228-summary-ranges/summary-ranges.go: -------------------------------------------------------------------------------- 1 | func summaryRanges(nums []int) []string { 2 | var output []string 3 | for i := 0; i < len(nums); i++ { 4 | j := i 5 | for (j + 1 < len(nums) && nums[j+1] == nums[j] + 1) { 6 | j++ 7 | } 8 | if i == j { 9 | output = append(output, fmt.Sprintf("%v", nums[i])) 10 | } else { 11 | output = append(output, fmt.Sprintf("%d->%d", nums[i], nums[j])) 12 | } 13 | i = j 14 | } 15 | return output 16 | } -------------------------------------------------------------------------------- /Golang/2308-divide-array-into-equal-pairs/divide-array-into-equal-pairs.go: -------------------------------------------------------------------------------- 1 | func divideArray(nums []int) bool { 2 | numsArr := make([]int, 501, 501) 3 | for _, num := range nums { 4 | numsArr[num]++ 5 | } 6 | for i := 1; i < 501; i++ { 7 | if numsArr[i] % 2 == 1 { 8 | return false 9 | } 10 | } 11 | return true 12 | } -------------------------------------------------------------------------------- /Golang/2331-intersection-of-multiple-arrays/intersection-of-multiple-arrays.go: -------------------------------------------------------------------------------- 1 | func intersection(nums [][]int) []int { 2 | numsArr := make([]int, 1001) 3 | output := make([]int, 0, len(nums[0])) 4 | for _, arr := range nums { 5 | for _, num := range arr { 6 | numsArr[num]++ 7 | } 8 | } 9 | for i := 1; i < 1001; i++ { 10 | if numsArr[i] == len(nums) { 11 | output = append(output, i) 12 | } 13 | } 14 | return output 15 | } -------------------------------------------------------------------------------- /Golang/2365-percentage-of-letter-in-string/percentage-of-letter-in-string.go: -------------------------------------------------------------------------------- 1 | func percentageLetter(s string, letter byte) int { 2 | count := 0; 3 | for i := 0; i < len(s); i++ { 4 | if s[i] == letter { 5 | count++ 6 | } 7 | } 8 | // fmt.Println("COUNT : ", count, "LENGTH : ", len(s)) 9 | return (count * 100) / len(s) 10 | } -------------------------------------------------------------------------------- /Golang/237-delete-node-in-a-linked-list/delete-node-in-a-linked-list.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * type ListNode struct { 4 | * Val int 5 | * Next *ListNode 6 | * } 7 | */ 8 | func deleteNode(node *ListNode) { 9 | *node = *node.Next 10 | } -------------------------------------------------------------------------------- /Golang/2383-add-two-integers/README.md: -------------------------------------------------------------------------------- 1 |

Add Two Integers

Difficulty: Easy
Given two integers num1 and num2, return the sum of the two integers. 2 |

 

3 |

Example 1:

4 | 5 |
 6 | Input: num1 = 12, num2 = 5
 7 | Output: 17
 8 | Explanation: num1 is 12, num2 is 5, and their sum is 12 + 5 = 17, so 17 is returned.
 9 | 
10 | 11 |

Example 2:

12 | 13 |
14 | Input: num1 = -10, num2 = 4
15 | Output: -6
16 | Explanation: num1 + num2 = -6, so -6 is returned.
17 | 
18 | 19 |

 

20 |

Constraints:

21 | 22 | 25 | -------------------------------------------------------------------------------- /Golang/2383-add-two-integers/add-two-integers.c: -------------------------------------------------------------------------------- 1 | int sum(int num1, int num2) { 2 | int sum; 3 | sum = num1 + num2; 4 | return sum; 5 | } -------------------------------------------------------------------------------- /Golang/2427-number-of-common-factors/README.md: -------------------------------------------------------------------------------- 1 |

Number of Common Factors

Difficulty: Easy

Given two positive integers a and b, return the number of common factors of a and b.

2 | 3 |

An integer x is a common factor of a and b if x divides both a and b.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
 9 | Input: a = 12, b = 6
10 | Output: 4
11 | Explanation: The common factors of 12 and 6 are 1, 2, 3, 6.
12 | 
13 | 14 |

Example 2:

15 | 16 |
17 | Input: a = 25, b = 30
18 | Output: 2
19 | Explanation: The common factors of 25 and 30 are 1, 5.
20 | 
21 | 22 |

 

23 |

Constraints:

24 | 25 | 28 | -------------------------------------------------------------------------------- /Golang/2427-number-of-common-factors/number-of-common-factors.go: -------------------------------------------------------------------------------- 1 | func commonFactors(a int, b int) int { 2 | count, low := 0, 0 3 | if a < b { 4 | low = a 5 | } else { 6 | low = b 7 | } 8 | for i := 1; i <= low; i++ { 9 | if a % i == 0 && b % i == 0 { 10 | count++ 11 | } 12 | } 13 | return count 14 | } -------------------------------------------------------------------------------- /Golang/2454-largest-local-values-in-a-matrix/largest-local-values-in-a-matrix.go: -------------------------------------------------------------------------------- 1 | func largestLocal(grid [][]int) [][]int { 2 | n := len(grid) 3 | // fmt.Println(n) 4 | output := make([][]int, (n-2), (n-2)) 5 | // fmt.Println(output) 6 | for i := 0; i < n-2; i++ { 7 | output[i] = make([]int, n-2) 8 | for j := 0; j < n-2; j++ { 9 | max := grid[i][j] 10 | for k := i; k < i+3; k++ { 11 | for l := j; l < j+3; l++ { 12 | if grid[k][l] > max { 13 | max = grid[k][l] 14 | } 15 | } 16 | } 17 | output[i][j] = max 18 | } 19 | 20 | } 21 | return output 22 | } -------------------------------------------------------------------------------- /Golang/2455-average-value-of-even-numbers-that-are-divisible-by-three/average-value-of-even-numbers-that-are-divisible-by-three.go: -------------------------------------------------------------------------------- 1 | func averageValue(nums []int) int { 2 | sum, count := 0, 0 3 | for _, num := range nums { 4 | if num % 2 == 0 && num % 3 == 0 { 5 | sum += num 6 | count++ 7 | } 8 | } 9 | if count == 0 { 10 | return 0 11 | } 12 | return int(sum / count) 13 | } -------------------------------------------------------------------------------- /Golang/2486-most-frequent-even-element/most-frequent-even-element.go: -------------------------------------------------------------------------------- 1 | func mostFrequentEven(nums []int) int { 2 | numsMap := make(map[int]int) 3 | for _, num := range nums { 4 | if num % 2 == 0 { 5 | numsMap[num]++ 6 | } 7 | } 8 | evenElement := -1 9 | count := 0 10 | for key, val := range numsMap { 11 | if val > count || (val == count && key < evenElement) { 12 | count = val 13 | evenElement = key 14 | } 15 | } 16 | return evenElement 17 | } -------------------------------------------------------------------------------- /Golang/2502-sort-the-people/sort-the-people.go: -------------------------------------------------------------------------------- 1 | func sortPeople(names []string, heights []int) []string { 2 | n := len(names) 3 | heightsMap := make(map[int]string) 4 | for idx, height := range heights { 5 | heightsMap[height] = names[idx] 6 | } 7 | sort.Ints(heights) 8 | output := make([]string, 0, n) 9 | for i := n-1; i >= 0; i-- { 10 | output = append(output, heightsMap[heights[i]]) 11 | } 12 | return output 13 | } -------------------------------------------------------------------------------- /Golang/2525-count-number-of-distinct-integers-after-reverse-operations/count-number-of-distinct-integers-after-reverse-operations.go: -------------------------------------------------------------------------------- 1 | func countDistinctIntegers(nums []int) int { 2 | numsMap := make(map[int]bool, len(nums)*2) 3 | for i := 0; i < len(nums); i++ { 4 | numsMap[nums[i]] = true 5 | numsMap[reverse(nums[i])] = true 6 | } 7 | return len(numsMap) 8 | } 9 | func reverse(num int) int { 10 | rev := 0 11 | for num > 0 { 12 | rev = (rev * 10) + (num % 10) 13 | num /= 10 14 | } 15 | return rev 16 | } -------------------------------------------------------------------------------- /Golang/2614-maximum-count-of-positive-integer-and-negative-integer/maximum-count-of-positive-integer-and-negative-integer.go: -------------------------------------------------------------------------------- 1 | func maximumCount(nums []int) int { 2 | pos, neg := 0, 0 3 | for _, num := range nums { 4 | if num < 0 { 5 | neg++ 6 | } else if num >0 { 7 | pos++ 8 | } 9 | } 10 | if neg > pos { 11 | return neg 12 | } 13 | return pos 14 | } -------------------------------------------------------------------------------- /Golang/2654-count-the-number-of-vowel-strings-in-range/count-the-number-of-vowel-strings-in-range.go: -------------------------------------------------------------------------------- 1 | func vowelStrings(words []string, left int, right int) int { 2 | count := 0 3 | for i := left; i <= right; i++ { 4 | word := words[i] 5 | last := len(word) - 1 6 | if (word[0] == 'a' || word[0] == 'e' || word[0] == 'i' || word[0] == 'o' || word[0] == 'u') && (word[last] == 'a' || word[last] == 'e' || word[last] == 'i' || word[last] == 'o' || word[last] == 'u') { 7 | count++ 8 | } 9 | } 10 | return count 11 | } -------------------------------------------------------------------------------- /Golang/27-remove-element/remove-element.go: -------------------------------------------------------------------------------- 1 | func removeElement(nums []int, val int) int { 2 | count := 0 3 | for _, num := range nums { 4 | if num != val { 5 | nums[count] = num 6 | count++ 7 | } 8 | } 9 | return count 10 | } -------------------------------------------------------------------------------- /Golang/2824-check-if-the-number-is-fascinating/check-if-the-number-is-fascinating.go: -------------------------------------------------------------------------------- 1 | func isFascinating(n int) bool { 2 | // num := make([]int, 10) 3 | // for temp := n; temp > 0; temp /= 10 { 4 | // num[(temp%10)]++ 5 | // } 6 | // for temp := 2*n; temp > 0; temp /= 10 { 7 | // num[(temp%10)]++ 8 | // } 9 | // for temp := 3*n; temp > 0; temp /= 10 { 10 | // num[(temp%10)]++ 11 | // } 12 | // // fmt.Println(num) 13 | // if num[0] > 0 { 14 | // return false 15 | // } 16 | // for i := 1; i < 10; i++ { 17 | // if num[i] > 1 { 18 | // return false 19 | // } 20 | // } 21 | // return true 22 | return n == 192 || n == 219 || n == 273 || n == 327 23 | } -------------------------------------------------------------------------------- /Golang/2825-minimize-string-length/minimize-string-length.go: -------------------------------------------------------------------------------- 1 | func minimizedStringLength(s string) int { 2 | charSet := make(map[rune]bool) 3 | for _, char := range s { 4 | charSet[char] = true 5 | } 6 | return len(charSet) 7 | } -------------------------------------------------------------------------------- /Golang/2887-sort-vowels-in-a-string/Notes.md: -------------------------------------------------------------------------------- 1 |

sort-vowels-in-a-string Notes


[ Time taken: 9 m 34 s ] -------------------------------------------------------------------------------- /Golang/292-nim-game/nim-game.go: -------------------------------------------------------------------------------- 1 | func canWinNim(n int) bool { 2 | if n <= 3 { 3 | return true 4 | } 5 | if n % 4 == 0 { 6 | return false 7 | } 8 | return true 9 | } -------------------------------------------------------------------------------- /Golang/3-longest-substring-without-repeating-characters/longest-substring-without-repeating-characters.go: -------------------------------------------------------------------------------- 1 | func lengthOfLongestSubstring(s string) int { 2 | maxLen := 0 3 | if len(s) == 0 { 4 | return 0 5 | } else if len(s) == 1 { 6 | return 1 7 | } 8 | count := make([]int, 256) 9 | for right, left := 0, 0; right < len(s); right++ { 10 | count[s[right]]++ 11 | for count[s[right]] > 1 { 12 | count[s[left]]-- 13 | left++ 14 | } 15 | if right-left+1 > maxLen { 16 | maxLen = right - left + 1 17 | } 18 | } 19 | return maxLen 20 | } -------------------------------------------------------------------------------- /Golang/3154-maximum-value-of-an-ordered-triplet-i/maximum-value-of-an-ordered-triplet-i.go: -------------------------------------------------------------------------------- 1 | func maximumTripletValue(nums []int) int64 { 2 | max := int64((nums[0] - nums[1]) * nums[2]) 3 | for i := 0; i < len(nums); i++ { 4 | for j := i+1; j < len(nums); j++ { 5 | for k := j+1; k < len(nums); k++ { 6 | temp := int64((nums[i] - nums[j]) * nums[k]) 7 | if temp > max { 8 | max = temp 9 | } 10 | } 11 | } 12 | } 13 | if max < 0 { 14 | return 0 15 | } 16 | return max 17 | } -------------------------------------------------------------------------------- /Golang/3165-find-indices-with-index-and-value-difference-i/find-indices-with-index-and-value-difference-i.go: -------------------------------------------------------------------------------- 1 | func findIndices(nums []int, indexDifference int, valueDifference int) []int { 2 | n := len(nums) 3 | for i := 0; i < n; i++ { 4 | for j := i + indexDifference; j < n; j++ { 5 | if (abs(nums[i] - nums[j])) >= valueDifference { 6 | return []int{i, j} 7 | } 8 | } 9 | } 10 | return []int{-1, -1} 11 | } 12 | func abs(num int) int { 13 | if num >= 0 { 14 | return num 15 | } 16 | return -num 17 | } -------------------------------------------------------------------------------- /Golang/3193-maximum-strong-pair-xor-i/maximum-strong-pair-xor-i.go: -------------------------------------------------------------------------------- 1 | func maximumStrongPairXor(nums []int) int { 2 | max := nums[0] ^ nums[0] 3 | for i := 0; i < len(nums); i++ { 4 | for j := i; j < len(nums); j++ { 5 | if mod(nums[i], nums[j]) <= min(nums[i], nums[j]) { 6 | if (nums[i] ^ nums[j]) > max { 7 | max = nums[i] ^ nums[j] 8 | } 9 | } 10 | } 11 | } 12 | return max 13 | } 14 | func min(a, b int) int { 15 | if a < b { 16 | return a 17 | } 18 | return b 19 | } 20 | func mod(a, b int) int { 21 | if a - b >= 0 { 22 | return a - b 23 | } 24 | return b - a 25 | } -------------------------------------------------------------------------------- /Golang/3199-distribute-candies-among-children-i/distribute-candies-among-children-i.go: -------------------------------------------------------------------------------- 1 | func distributeCandies(n int, limit int) int { 2 | result := 0 3 | for i := 0; i <= limit; i++ { 4 | for j := 0; j <= limit; j++ { 5 | for k := 0; k <= limit; k++ { 6 | if i+j+k == n { 7 | result++ 8 | } else if i+j+k > n { 9 | break 10 | } 11 | } 12 | } 13 | } 14 | 15 | return result 16 | } -------------------------------------------------------------------------------- /Golang/3206-find-common-elements-between-two-arrays/find-common-elements-between-two-arrays.go: -------------------------------------------------------------------------------- 1 | func findIntersectionValues(nums1 []int, nums2 []int) []int { 2 | nums1Arr, nums2Arr := make([]bool, 101, 101), make([]bool, 101, 101) 3 | answer := make([]int, 2, 2) 4 | for _, num := range nums1 { 5 | nums1Arr[num] = true 6 | } 7 | for _, num := range nums2 { 8 | nums2Arr[num] = true 9 | } 10 | for _, num := range nums1 { 11 | if nums2Arr[num] { 12 | answer[0]++ 13 | } 14 | } 15 | for _, num := range nums2 { 16 | if nums1Arr[num] { 17 | answer[1]++ 18 | } 19 | } 20 | return answer 21 | } -------------------------------------------------------------------------------- /Golang/3220-count-tested-devices-after-test-operations/count-tested-devices-after-test-operations.go: -------------------------------------------------------------------------------- 1 | func countTestedDevices(batteryPercentages []int) int { 2 | count := 0 3 | for i, n := 0, len(batteryPercentages); i < n; i++ { 4 | if batteryPercentages[i] - count > 0 { 5 | count++ 6 | } 7 | } 8 | return count 9 | } -------------------------------------------------------------------------------- /Golang/3221-find-the-peaks/find-the-peaks.go: -------------------------------------------------------------------------------- 1 | func findPeaks(mountain []int) []int { 2 | size := len(mountain) 3 | result := make([]int, 0, size-2) 4 | for i := 1; i < size-1; i++ { 5 | if (mountain[i] > mountain[i - 1]) && (mountain[i] > mountain[i + 1]) { 6 | result = append(result, i) 7 | } 8 | } 9 | return result 10 | } -------------------------------------------------------------------------------- /Golang/3361-latest-time-you-can-obtain-after-replacing-characters/latest-time-you-can-obtain-after-replacing-characters.go: -------------------------------------------------------------------------------- 1 | func findLatestTime(s string) string { 2 | str := []byte(s) 3 | if str[0] == '?' { 4 | if str[1] == '0' || str[1] == '?' || str[1] == '1' { 5 | str[0] = '1' 6 | } else { 7 | str[0] = '0' 8 | } 9 | } 10 | if str[1] == '?' { 11 | if str[0] == '0' { 12 | str[1] = '9' 13 | } else if str[0] == '1' { 14 | str[1] = '1' 15 | } 16 | } 17 | if str[3] == '?' { 18 | str[3] = '5' 19 | } 20 | if str[4] == '?' { 21 | str[4] = '9' 22 | } 23 | return string(str) 24 | } -------------------------------------------------------------------------------- /Golang/3367-find-the-sum-of-encrypted-integers/find-the-sum-of-encrypted-integers.go: -------------------------------------------------------------------------------- 1 | func sumOfEncryptedInt(nums []int) int { 2 | sum := 0 3 | for _, num := range nums { 4 | sum += encrypt(num) 5 | } 6 | return sum 7 | } 8 | func encrypt(num int) int { 9 | count, large := 0, 0 10 | for num > 0 { 11 | if num % 10 > large { 12 | large = num % 10 13 | } 14 | num /= 10 15 | count++ 16 | } 17 | for i:=1; i= 0; i-- { 11 | if checkPrime(nums[i]) { 12 | //fmt.Println(nums[i]) 13 | right = i 14 | break 15 | } 16 | } 17 | return right - left 18 | } 19 | func checkPrime(num int) bool { 20 | if num == 1 { 21 | return false 22 | }else if num == 2 || num == 3 { 23 | return true 24 | } 25 | for i := 2; i <= int(math.Sqrt(float64(num))); i++ { 26 | if num % i == 0 { 27 | return false 28 | } 29 | } 30 | return true 31 | } -------------------------------------------------------------------------------- /Golang/3383-taking-maximum-energy-from-the-mystic-dungeon/taking-maximum-energy-from-the-mystic-dungeon.go: -------------------------------------------------------------------------------- 1 | func maximumEnergy(energy []int, k int) int { 2 | maxEnergy := -1001 3 | size := len(energy) 4 | for i := k; i < size; i++ { 5 | val := energy[i] + energy[i-k] 6 | if val > energy[i] { 7 | energy[i] = val 8 | } 9 | } 10 | for i := size - 1; i >= size - k; i-- { 11 | if energy[i] > maxEnergy { 12 | maxEnergy = energy[i] 13 | } 14 | } 15 | return maxEnergy 16 | } -------------------------------------------------------------------------------- /Golang/3396-valid-word/valid-word.go: -------------------------------------------------------------------------------- 1 | func isValid(word string) bool { 2 | if len(word) < 3 { 3 | return false 4 | } 5 | vowelMap := map[byte]bool{'a': true, 'e': true, 'i': true, 'o': true, 'u': true, 'A': true, 'E': true, 'I': true, 'O': true, 'U': true} 6 | vowel, consonant := false, false 7 | for i := 0; i < len(word); i++ { 8 | if vowelMap[word[i]] { 9 | vowel = true 10 | } else if word[i] >= 'a' && word[i] <= 'z' || word[i] >= 'A' && word[i] <= 'Z' { 11 | consonant = true 12 | } else if word[i] >= '0' && word[i] <= '9' { 13 | continue 14 | } else { 15 | return false 16 | } 17 | } 18 | if vowel && consonant { 19 | return true 20 | } 21 | return false 22 | } -------------------------------------------------------------------------------- /Golang/3397-find-the-integer-added-to-array-i/find-the-integer-added-to-array-i.go: -------------------------------------------------------------------------------- 1 | func addedInteger(nums1 []int, nums2 []int) int { 2 | sum1, sum2, size := 0, 0, len(nums1) 3 | for i := 0; i < size; i++ { 4 | sum1 += nums1[i] 5 | sum2 += nums2[i] 6 | } 7 | return (sum2 - sum1) / size 8 | } -------------------------------------------------------------------------------- /Golang/3398-make-a-square-with-the-same-color/make-a-square-with-the-same-color.go: -------------------------------------------------------------------------------- 1 | func canMakeSquare(grid [][]byte) bool { 2 | for i := 0; i < 2; i++ { 3 | black, white := 0, 0 4 | for j := 0; j < 2; j++ { 5 | if grid[i][j] == 'W' { 6 | white++ 7 | } else { 8 | black++ 9 | } 10 | if grid[i+1][j] == 'W' { 11 | white++ 12 | } else { 13 | black++ 14 | } 15 | } 16 | if black >= 3 || white >= 3 { 17 | return true 18 | } 19 | black, white = 0, 0 20 | for j := 1; j < 3; j++ { 21 | if grid[i][j] == 'W' { 22 | white++ 23 | } else { 24 | black++ 25 | } 26 | if grid[i+1][j] == 'W' { 27 | white++ 28 | } else { 29 | black++ 30 | } 31 | } 32 | if black >= 3 || white >= 3 { 33 | return true 34 | } 35 | } 36 | return false 37 | } -------------------------------------------------------------------------------- /Golang/3405-count-the-number-of-special-characters-ii/count-the-number-of-special-characters-ii.go: -------------------------------------------------------------------------------- 1 | func numberOfSpecialChars(word string) int { 2 | small, capital := [26]int{}, [26]int{} 3 | count := 0 4 | for i, char := range word { 5 | if char >= 'a' && char <= 'z' { 6 | small[int(char - 'a')] = i+1 7 | } else { 8 | if capital[int(char - 'A')] == 0 { 9 | capital[int(char - 'A')] = i+1 10 | } 11 | } 12 | } 13 | for i := 0; i < 26; i++ { 14 | if small[i] != 0 && capital[i] > small[i] { 15 | count++ 16 | } 17 | } 18 | return count 19 | } -------------------------------------------------------------------------------- /Golang/3408-count-the-number-of-special-characters-i/count-the-number-of-special-characters-i.go: -------------------------------------------------------------------------------- 1 | func numberOfSpecialChars(word string) int { 2 | small, capital := [26]int{}, [26]int{} 3 | count := 0 4 | for _, char := range word { 5 | if char >= 'a' && char <= 'z' { 6 | small[int(char - 'a')] = 1 7 | } else if char >= 'A' && char <= 'Z' { 8 | capital[int(char - 'A')] = 1 9 | } 10 | } 11 | for i := 0; i < 26; i++ { 12 | if small[i] == 1 && capital[i] == 1 { 13 | count++ 14 | } 15 | } 16 | return count 17 | } -------------------------------------------------------------------------------- /Golang/3415-check-if-grid-satisfies-conditions/check-if-grid-satisfies-conditions.go: -------------------------------------------------------------------------------- 1 | func satisfiesConditions(grid [][]int) bool { 2 | column, row := len(grid[0]), len(grid) 3 | for i := 0; i < row-1; i++ { 4 | for j := 0; j < column; j++ { 5 | if grid[i][j] != grid[i+1][j] { 6 | return false 7 | } 8 | if j < column-1 && grid[i][j] == grid[i][j+1] { 9 | return false 10 | } 11 | } 12 | } 13 | for j := 0; j < column-1; j++ { 14 | if grid[row-1][j] == grid[row-1][j+1] { 15 | return false 16 | } 17 | } 18 | return true 19 | } 20 | -------------------------------------------------------------------------------- /Golang/3415-check-if-grid-satisfies-conditions/check-if-grid-satisfies-conditions.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean satisfiesConditions(int[][] grid) { 3 | int m = grid.length; 4 | int n = grid[0].length; 5 | for (int i = 0; i < m - 1; i++) { 6 | for (int j = 0; j < n; j++) { 7 | if (grid[i][j] != grid[i + 1][j]) { 8 | return false; 9 | } 10 | if (j < n - 1 && grid[i][j] == grid[i][j + 1]) { 11 | return false; 12 | } 13 | } 14 | } 15 | for (int j = 0; j < n - 1; j++) { 16 | if (grid[m - 1][j] == grid[m - 1][j + 1]) { 17 | return false; 18 | } 19 | } 20 | return true; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Golang/3416-sum-of-digit-differences-of-all-pairs/sum-of-digit-differences-of-all-pairs.go: -------------------------------------------------------------------------------- 1 | func sumDigitDifferences(nums []int) int64 { 2 | var output int64 3 | // arrSize := len(nums) 4 | digitLen := 0 5 | for temp := nums[0]; temp > 0; temp /= 10 { 6 | digitLen++ 7 | } 8 | digitFreq := make([][]int, digitLen) 9 | for idx := range digitFreq { 10 | digitFreq[idx] = make([]int, 10) 11 | } 12 | // fmt.Println(digitFreq) 13 | // fmt.Println("Arr Size : ", arrSize) 14 | for idx, num := range nums { 15 | n := strconv.Itoa(num) 16 | for i := 0; i < len(n); i++ { 17 | digit, _ := strconv.Atoi(string(n[i])) 18 | output += int64(idx - digitFreq[i][digit]) 19 | digitFreq[i][digit]++ 20 | } 21 | } 22 | fmt.Println(digitFreq) 23 | return output 24 | } 25 | // func findSum(num1, num2 int) int64 { 26 | // var sum int64 27 | // for num1 > 0 { 28 | // digit1 := num1 % 10 29 | // digit2 := num2 % 10 30 | // if digit1 != digit2 { 31 | // sum++ 32 | // } 33 | // num1 /= 10 34 | // num2 /= 10 35 | // } 36 | // // fmt.Println("num1 : ",num1, "num2 : ", num2, " : ",sum) 37 | // return sum 38 | // } -------------------------------------------------------------------------------- /Golang/3418-count-pairs-that-form-a-complete-day-ii/count-pairs-that-form-a-complete-day-ii.go: -------------------------------------------------------------------------------- 1 | func countCompleteDayPairs(hours []int) int64 { 2 | seenMap := make(map[int]int) 3 | count := int64(0) 4 | 5 | for _, hour := range hours { 6 | rem := hour % 24 7 | complement := (24 - rem) % 24 8 | 9 | if _, ok := seenMap[complement]; ok { 10 | count += int64(seenMap[complement]) 11 | } 12 | seenMap[rem]++ 13 | } 14 | 15 | return count 16 | } 17 | -------------------------------------------------------------------------------- /Golang/3427-special-array-ii/special-array-ii.go: -------------------------------------------------------------------------------- 1 | func isArraySpecial(nums []int, queries [][]int) []bool { 2 | size := len(nums) 3 | parityArr := make([]int, size) 4 | for i := 1; i < size; i++ { 5 | parityArr[i] = parityArr[i-1] 6 | if nums[i] % 2 == nums[i-1] % 2 { 7 | parityArr[i]++ 8 | } 9 | } 10 | output := make([]bool, len(queries)) 11 | for i := 0; i < len(queries); i++ { 12 | if parityArr[queries[i][1]] - parityArr[queries[i][0]] == 0 { 13 | output[i] = true 14 | } 15 | } 16 | return output 17 | } -------------------------------------------------------------------------------- /Golang/3434-find-the-number-of-distinct-colors-among-the-balls/find-the-number-of-distinct-colors-among-the-balls.go: -------------------------------------------------------------------------------- 1 | func queryResults(limit int, queries [][]int) []int { 2 | ballColors := make(map[int]int) 3 | colorCount := make(map[int]int) 4 | result := make([]int, len(queries)) 5 | distinctColors := 0 6 | 7 | for i, query := range queries { 8 | ball := query[0] 9 | color := query[1] 10 | 11 | if prevColor, exists := ballColors[ball]; exists { 12 | colorCount[prevColor]-- 13 | if colorCount[prevColor] == 0 { 14 | distinctColors-- 15 | } 16 | } 17 | 18 | ballColors[ball] = color 19 | colorCount[color]++ 20 | if colorCount[color] == 1 { 21 | distinctColors++ 22 | } 23 | 24 | result[i] = distinctColors 25 | } 26 | 27 | return result 28 | } -------------------------------------------------------------------------------- /Golang/3447-clear-digits/clear-digits.go: -------------------------------------------------------------------------------- 1 | func clearDigits(s string) string { 2 | var result []rune 3 | 4 | for _, char := range s { 5 | if char >= '0' && char <= '9' { 6 | 7 | if len(result) > 0 && result[len(result)-1] >= 'a' && result[len(result)-1] <= 'z' { 8 | result = result[:len(result)-1] 9 | } 10 | 11 | } else { 12 | result = append(result, char) 13 | } 14 | } 15 | return string(result) 16 | 17 | } -------------------------------------------------------------------------------- /Golang/3450-find-the-child-who-has-the-ball-after-k-seconds/find-the-child-who-has-the-ball-after-k-seconds.go: -------------------------------------------------------------------------------- 1 | func numberOfChild(n int, k int) int { 2 | k = k % (2 * (n - 1)) 3 | if k < n { 4 | return k 5 | } 6 | return (2 * (n - 1)) - k 7 | } -------------------------------------------------------------------------------- /Golang/3463-alternating-groups-i/alternating-groups-i.go: -------------------------------------------------------------------------------- 1 | func numberOfAlternatingGroups(colors []int) int { 2 | n := len(colors) 3 | if n < 3 { 4 | return 0 5 | } 6 | 7 | ans := 0 8 | for i := 0; i < n-2; i++ { 9 | if colors[i] == colors[i+2] && colors[i] != colors[i+1] { 10 | ans++ 11 | } 12 | } 13 | 14 | if colors[0] == colors[n-2] && colors[0] != colors[n-1] { 15 | ans++ 16 | } 17 | 18 | if colors[0] != colors[1] && colors[1] == colors[n-1] { 19 | ans++ 20 | } 21 | 22 | return ans 23 | } 24 | -------------------------------------------------------------------------------- /Golang/3468-find-the-encrypted-string/find-the-encrypted-string.go: -------------------------------------------------------------------------------- 1 | func getEncryptedString(s string, k int) string { 2 | n := len(s) 3 | result := make([]byte, n) 4 | for i := 0; i < n; i++ { 5 | idx := (i + k) % n 6 | result[i] = s[idx] 7 | } 8 | return string(result) 9 | } -------------------------------------------------------------------------------- /Golang/3469-maximum-height-of-a-triangle/maximum-height-of-a-triangle.go: -------------------------------------------------------------------------------- 1 | func maxHeightOfTriangle(red int, blue int) int { 2 | return max(helper(red, blue), helper(blue, red)) 3 | } 4 | 5 | func helper(red int, blue int) int { 6 | h := 0 7 | i := 1 8 | 9 | for { 10 | if i % 2 == 1 { 11 | if red >= i { 12 | red -= i 13 | } else { 14 | break 15 | } 16 | } else { 17 | if blue >= i { 18 | blue -= i 19 | } else { 20 | break 21 | } 22 | } 23 | h++ 24 | i++ 25 | } 26 | 27 | return h 28 | } 29 | 30 | func max(a, b int) int { 31 | if a > b { 32 | return a 33 | } 34 | return b 35 | } -------------------------------------------------------------------------------- /Golang/3471-minimum-average-of-smallest-and-largest-elements/minimum-average-of-smallest-and-largest-elements.go: -------------------------------------------------------------------------------- 1 | func minimumAverage(nums []int) float64 { 2 | n := len(nums) 3 | var minAvg float64 4 | sort.Ints(nums) 5 | //fmt.Println(nums) 6 | //fmt.Println(avgArr) 7 | minAvg = float64(nums[0] + nums[n-1]) / float64(2) 8 | for i := 1; i < (n/2); i++ { 9 | avg := float64(nums[i] + nums[n-1-i]) / float64(2) 10 | if avg < minAvg { 11 | minAvg = avg 12 | } 13 | } 14 | return minAvg 15 | 16 | } -------------------------------------------------------------------------------- /Golang/3501-delete-nodes-from-linked-list-present-in-array/delete-nodes-from-linked-list-present-in-array.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * type ListNode struct { 4 | * Val int 5 | * Next *ListNode 6 | * } 7 | */ 8 | func modifiedList(nums []int, head *ListNode) *ListNode { 9 | numSet := make(map[int]bool) 10 | for _, num := range nums { 11 | numSet[num] = true 12 | } 13 | 14 | temp := &ListNode{Next: head} 15 | prev := temp 16 | curr := head 17 | 18 | for curr != nil { 19 | if _, exists := numSet[curr.Val]; exists { 20 | prev.Next = curr.Next 21 | } else { 22 | prev = curr 23 | } 24 | curr = curr.Next 25 | } 26 | 27 | return temp.Next 28 | } 29 | -------------------------------------------------------------------------------- /Golang/3508-number-of-bit-changes-to-make-two-integers-equal/number-of-bit-changes-to-make-two-integers-equal.go: -------------------------------------------------------------------------------- 1 | func minChanges(n int, k int) int { 2 | if n == k { 3 | return 0 4 | } 5 | 6 | count := 0 7 | 8 | for n > 0 || k > 0 { 9 | bitN := n & 1 10 | bitK := k & 1 11 | 12 | if bitK == 1 && bitN == 0 { 13 | return -1 14 | } 15 | 16 | if bitN == 1 && bitK == 0 { 17 | count++ 18 | } 19 | 20 | n >>= 1 21 | k >>= 1 22 | } 23 | 24 | return count 25 | } -------------------------------------------------------------------------------- /Golang/3511-find-the-winning-player-in-coin-game/find-the-winning-player-in-coin-game.go: -------------------------------------------------------------------------------- 1 | func losingPlayer(x int, y int) string { 2 | for turn := 0; ; turn++ { 3 | if x >= 1 && y >= 4 { 4 | x -= 1 5 | y -= 4 6 | } else { 7 | if turn % 2 == 0 { 8 | return "Bob" 9 | } else { 10 | return "Alice" 11 | } 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Golang/3515-find-if-digit-game-can-be-won/find-if-digit-game-can-be-won.go: -------------------------------------------------------------------------------- 1 | func canAliceWin(nums []int) bool { 2 | singleSum, doubleSum := 0, 0 3 | for _, num := range nums { 4 | if num < 10 { 5 | singleSum += num 6 | } else { 7 | doubleSum += num 8 | } 9 | } 10 | return singleSum != doubleSum 11 | } -------------------------------------------------------------------------------- /Golang/3519-find-the-number-of-winning-players/find-the-number-of-winning-players.go: -------------------------------------------------------------------------------- 1 | func winningPlayerCount(n int, pick [][]int) int { 2 | playerColors := make([][]int, n) 3 | for i := 0; i < n; i++ { 4 | playerColors[i] = make([]int, 11) 5 | } 6 | for _, player := range pick { 7 | playerColors[player[0]][player[1]]++ 8 | } 9 | count := 0 10 | for i := 0; i < n; i++ { 11 | for _, val := range playerColors[i] { 12 | if val > i { 13 | count++ 14 | break 15 | } 16 | } 17 | } 18 | return count 19 | } -------------------------------------------------------------------------------- /Golang/3533-snake-in-matrix/snake-in-matrix.go: -------------------------------------------------------------------------------- 1 | func finalPositionOfSnake(n int, commands []string) int { 2 | pos := 0 3 | for _, command := range commands { 4 | if command == "RIGHT" { 5 | pos++ 6 | } else if command == "LEFT" { 7 | pos-- 8 | } else if command == "UP" { 9 | pos -= n 10 | } else { 11 | pos += n 12 | } 13 | } 14 | return pos 15 | } -------------------------------------------------------------------------------- /Golang/3553-check-if-two-chessboard-squares-have-the-same-color/check-if-two-chessboard-squares-have-the-same-color.go: -------------------------------------------------------------------------------- 1 | func checkTwoChessboards(coordinate1 string, coordinate2 string) bool { 2 | val1 := (int(coordinate1[0]) - int('a') + int(coordinate1[1]) + 1) 3 | val2 := (int(coordinate2[0]) - int('a') + int(coordinate2[1]) + 1) 4 | if (val1 % 2 == 0 && val2 % 2 == 0) || (val1 % 2 == 1 && val2 % 2 == 1) { 5 | return true 6 | } 7 | return false 8 | } -------------------------------------------------------------------------------- /Golang/3555-final-array-state-after-k-multiplication-operations-i/final-array-state-after-k-multiplication-operations-i.go: -------------------------------------------------------------------------------- 1 | func getFinalState(nums []int, k int, multiplier int) []int { 2 | for i := 1; i <= k; i++ { 3 | idx := minim(nums) 4 | nums[idx] *= multiplier 5 | } 6 | return nums 7 | } 8 | func minim(nums []int) int { 9 | low := 0 10 | for i, num := range nums { 11 | if num < nums[low] { 12 | low = i 13 | } 14 | } 15 | return low 16 | } -------------------------------------------------------------------------------- /Golang/3567-convert-date-to-binary/convert-date-to-binary.go: -------------------------------------------------------------------------------- 1 | func convertDateToBinary(date string) string { 2 | // output := "" 3 | // output += convert(date[:4]) + "-" + convert(date[5:7]) + "-" + convert(date[8:10]) 4 | fmt.Println(convert(date[:4])) 5 | // fmt.Println((date[5:7])) 6 | // fmt.Println((date[8:10])) 7 | // fmt.Println(output) 8 | return fmt.Sprintf("%v-%v-%v",convert(date[:4]),convert(date[5:7]),convert(date[8:10])) 9 | } 10 | 11 | func convert(val string) string { 12 | res := "" 13 | num, _ := strconv.Atoi(val) 14 | for num > 0 { 15 | res = strconv.Itoa(num % 2) + res 16 | num /= 2 17 | } 18 | return res 19 | } -------------------------------------------------------------------------------- /Golang/3568-find-the-key-of-the-numbers/find-the-key-of-the-numbers.go: -------------------------------------------------------------------------------- 1 | func generateKey(num1 int, num2 int, num3 int) int { 2 | output := [4]int{} 3 | result := 0 4 | for i := 1; i <= 4; i++ { 5 | output[4-i] = minim(num1 % 10, num2 % 10, num3 % 10) 6 | num1 /= 10 7 | num2 /= 10 8 | num3 /= 10 9 | } 10 | for _, digit := range output { 11 | result = result * 10 + digit 12 | } 13 | return result 14 | } 15 | 16 | func minim(num1, num2, num3 int) int { 17 | if num1 < num2 { 18 | if num1 < num3 { 19 | return num1 20 | } else { 21 | return num3 22 | } 23 | } else if num2 < num3 { 24 | return num2 25 | } 26 | return num3 27 | } -------------------------------------------------------------------------------- /Golang/3581-the-two-sneaky-numbers-of-digitville/the-two-sneaky-numbers-of-digitville.go: -------------------------------------------------------------------------------- 1 | func getSneakyNumbers(nums []int) []int { 2 | numsArr := make([]int, 101, 101) 3 | output := make([]int, 0, 2) 4 | for _, num := range nums { 5 | numsArr[num]++ 6 | if numsArr[num] == 2 { 7 | output = append(output, num) 8 | } 9 | } 10 | return output 11 | } -------------------------------------------------------------------------------- /Golang/3582-find-indices-of-stable-mountains/find-indices-of-stable-mountains.go: -------------------------------------------------------------------------------- 1 | func stableMountains(height []int, threshold int) []int { 2 | output := make([]int, 0, len(height)) 3 | for i := 1; i < len(height); i++ { 4 | if height[i-1] > threshold { 5 | output = append(output, i) 6 | } 7 | } 8 | return output 9 | } -------------------------------------------------------------------------------- /Golang/3606-minimum-element-after-replacement-with-digit-sum/minimum-element-after-replacement-with-digit-sum.go: -------------------------------------------------------------------------------- 1 | func minElement(nums []int) int { 2 | temp, sum := nums[0], 0 3 | for temp > 0 { 4 | val := temp % 10 5 | sum += val 6 | temp /= 10 7 | } 8 | min := sum 9 | for _, num := range nums { 10 | temp, sum = num, 0 11 | for temp > 0 { 12 | val := temp % 10 13 | sum += val 14 | temp /= 10 15 | } 16 | if min > sum { 17 | min = sum 18 | } 19 | } 20 | return min 21 | } -------------------------------------------------------------------------------- /Golang/3636-check-balanced-string/check-balanced-string.go: -------------------------------------------------------------------------------- 1 | func isBalanced(num string) bool { 2 | var odd byte 3 | var even byte 4 | for i := 0; i < len(num); i++ { 5 | if i % 2 == 0 { 6 | even += num[i] - '0' 7 | } else { 8 | odd += num[i] - '0' 9 | } 10 | } 11 | // fmt.Println("odd : ",odd,"\teven : ",even) 12 | if odd == even { 13 | return true 14 | } 15 | return false 16 | } -------------------------------------------------------------------------------- /Golang/378-kth-smallest-element-in-a-sorted-matrix/kth-smallest-element-in-a-sorted-matrix.go: -------------------------------------------------------------------------------- 1 | func kthSmallest(matrix [][]int, k int) int { 2 | size := len(matrix[0]) 3 | arr := make([]int, 0, (size*size)) 4 | for _, row := range matrix { 5 | for _, element := range row { 6 | arr = append(arr, element) 7 | } 8 | } 9 | sort.Ints(arr) 10 | return arr[k-1] 11 | } -------------------------------------------------------------------------------- /Golang/4-median-of-two-sorted-arrays/median-of-two-sorted-arrays.go: -------------------------------------------------------------------------------- 1 | func findMedianSortedArrays(nums1 []int, nums2 []int) float64 { 2 | m, n := len(nums1), len(nums2) 3 | var median float64 4 | arr := make([]int, 0, (m+n)) 5 | arr = append(nums1, nums2...) 6 | sort.Ints(arr) 7 | fmt.Println(arr) 8 | if size := len(arr); size % 2 == 1 { 9 | median = float64(arr[(size/2)]) 10 | fmt.Println(median) 11 | } else { 12 | val := float64(arr[size/2]) / 2 + float64(arr[(size/2)-1]) / 2 13 | fmt.Println("values : ", arr[size/2], arr[(size/2)-1]) 14 | median = float64(val) 15 | fmt.Println("median : ", median) 16 | } 17 | return median 18 | } -------------------------------------------------------------------------------- /Golang/48-rotate-image/rotate-image.go: -------------------------------------------------------------------------------- 1 | func rotate(matrix [][]int) { 2 | n := len(matrix[0]) 3 | for i := 0; i < n; i++ { 4 | for j := 0; j < i; j++ { 5 | matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] 6 | } 7 | } 8 | for i := 0; i < n; i++ { 9 | for j := 0; j < n/2; j++ { 10 | matrix[i][j], matrix[i][n-j-1] = matrix[i][n-j-1], matrix[i][j] 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /Golang/485-max-consecutive-ones/README.md: -------------------------------------------------------------------------------- 1 |

Max Consecutive Ones

Difficulty: Easy

Given a binary array nums, return the maximum number of consecutive 1's in the array.

2 | 3 |

 

4 |

Example 1:

5 | 6 |
 7 | Input: nums = [1,1,0,1,1,1]
 8 | Output: 3
 9 | Explanation: The first two digits or the last three digits are consecutive 1s. The maximum number of consecutive 1s is 3.
10 | 
11 | 12 |

Example 2:

13 | 14 |
15 | Input: nums = [1,0,1,1,0,1]
16 | Output: 2
17 | 
18 | 19 |

 

20 |

Constraints:

21 | 22 |
    23 |
  • 1 <= nums.length <= 105
  • 24 |
  • nums[i] is either 0 or 1.
  • 25 |
26 | -------------------------------------------------------------------------------- /Golang/485-max-consecutive-ones/max-consecutive-ones.go: -------------------------------------------------------------------------------- 1 | func findMaxConsecutiveOnes(nums []int) int { 2 | count, maxCount := 0, 0 3 | for _, num := range nums { 4 | count = count * num + num 5 | if count > maxCount { 6 | maxCount = count 7 | } 8 | } 9 | return maxCount 10 | } -------------------------------------------------------------------------------- /Golang/496-next-greater-element-i/next-greater-element-i.go: -------------------------------------------------------------------------------- 1 | func nextGreaterElement(nums1 []int, nums2 []int) []int { 2 | nums2Map := map[int]int{} 3 | 4 | for i, num := range nums2 { 5 | nums2Map[num] = i 6 | } 7 | 8 | result := make([]int, len(nums1)) 9 | for i, num := range nums1 { 10 | found := false 11 | for nextIndex := nums2Map[num] + 1; nextIndex < len(nums2); nextIndex++ { 12 | if nums2[nextIndex] > num { 13 | result[i] = nums2[nextIndex] 14 | found = true 15 | break 16 | } 17 | } 18 | 19 | if !found { 20 | result[i] = -1 21 | } 22 | } 23 | 24 | return result 25 | } -------------------------------------------------------------------------------- /Golang/50-powx-n/README.md: -------------------------------------------------------------------------------- 1 |

Pow(x, n)

Difficulty: Medium

Implement pow(x, n), which calculates x raised to the power n (i.e., xn).

2 | 3 |

 

4 |

Example 1:

5 | 6 |
 7 | Input: x = 2.00000, n = 10
 8 | Output: 1024.00000
 9 | 
10 | 11 |

Example 2:

12 | 13 |
14 | Input: x = 2.10000, n = 3
15 | Output: 9.26100
16 | 
17 | 18 |

Example 3:

19 | 20 |
21 | Input: x = 2.00000, n = -2
22 | Output: 0.25000
23 | Explanation: 2-2 = 1/22 = 1/4 = 0.25
24 | 
25 | 26 |

 

27 |

Constraints:

28 | 29 |
    30 |
  • -100.0 < x < 100.0
  • 31 |
  • -231 <= n <= 231-1
  • 32 |
  • n is an integer.
  • 33 |
  • Either x is not zero or n > 0.
  • 34 |
  • -104 <= xn <= 104
  • 35 |
36 | -------------------------------------------------------------------------------- /Golang/50-powx-n/powx-n.go: -------------------------------------------------------------------------------- 1 | func myPow(x float64, n int) float64 { 2 | if x == 0 { 3 | return float64(0) 4 | } 5 | if n == 0 { 6 | return float64(1) 7 | } 8 | var result float64 9 | result = math.Pow(x, float64(n)) 10 | return result 11 | } -------------------------------------------------------------------------------- /Golang/507-perfect-number/README.md: -------------------------------------------------------------------------------- 1 |

Perfect Number

Difficulty: Easy

A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. A divisor of an integer x is an integer that can divide x evenly.

2 | 3 |

Given an integer n, return true if n is a perfect number, otherwise return false.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
 9 | Input: num = 28
10 | Output: true
11 | Explanation: 28 = 1 + 2 + 4 + 7 + 14
12 | 1, 2, 4, 7, and 14 are all divisors of 28.
13 | 
14 | 15 |

Example 2:

16 | 17 |
18 | Input: num = 7
19 | Output: false
20 | 
21 | 22 |

 

23 |

Constraints:

24 | 25 |
    26 |
  • 1 <= num <= 108
  • 27 |
28 | -------------------------------------------------------------------------------- /Golang/507-perfect-number/perfect-number.go: -------------------------------------------------------------------------------- 1 | func checkPerfectNumber(num int) bool { 2 | if num == 1 { 3 | return false 4 | } 5 | sum := 0 6 | for i:=1; i*i <= num; i++ { 7 | if num % i == 0 { 8 | sum += i + (num / i) 9 | } 10 | } 11 | //fmt.Println(sum) 12 | return sum-num == num 13 | } -------------------------------------------------------------------------------- /Golang/521-longest-uncommon-subsequence-i/longest-uncommon-subsequence-i.go: -------------------------------------------------------------------------------- 1 | func findLUSlength(a string, b string) int { 2 | if a == b { 3 | return -1 4 | } 5 | if len(a) > len(b) { 6 | return len(a) 7 | } 8 | return len(b) 9 | } -------------------------------------------------------------------------------- /Golang/53-maximum-subarray/maximum-subarray.go: -------------------------------------------------------------------------------- 1 | func maxSubArray(nums []int) int { 2 | if len(nums) == 1 { 3 | return nums[0] 4 | } 5 | maxCurr, maxGlobal := nums[0], nums[0] 6 | for i := 1; i < len(nums); i++ { 7 | if maxCurr < 0 { 8 | maxCurr = 0 9 | } 10 | maxCurr += nums[i] 11 | if maxCurr > maxGlobal { 12 | maxGlobal = maxCurr 13 | } 14 | } 15 | return maxGlobal 16 | } -------------------------------------------------------------------------------- /Golang/567-permutation-in-string/README.md: -------------------------------------------------------------------------------- 1 |

Permutation in String

Difficulty: Medium

Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise.

2 | 3 |

In other words, return true if one of s1's permutations is the substring of s2.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
 9 | Input: s1 = "ab", s2 = "eidbaooo"
10 | Output: true
11 | Explanation: s2 contains one permutation of s1 ("ba").
12 | 
13 | 14 |

Example 2:

15 | 16 |
17 | Input: s1 = "ab", s2 = "eidboaoo"
18 | Output: false
19 | 
20 | 21 |

 

22 |

Constraints:

23 | 24 |
    25 |
  • 1 <= s1.length, s2.length <= 104
  • 26 |
  • s1 and s2 consist of lowercase English letters.
  • 27 |
28 | -------------------------------------------------------------------------------- /Golang/567-permutation-in-string/permutation-in-string.go: -------------------------------------------------------------------------------- 1 | func checkInclusion(s1 string, s2 string) bool { 2 | l1, l2 := len(s1), len(s2) 3 | if l1 > l2 { 4 | return false 5 | } 6 | s1Array, s2Array := [26]int{}, [26]int{} 7 | for i:=0; i 0 { 10 | lastLength = current 11 | } 12 | } 13 | return lastLength 14 | } -------------------------------------------------------------------------------- /Golang/620-not-boring-movies/not-boring-movies.sql: -------------------------------------------------------------------------------- 1 | -- Write your PostgreSQL query statement below 2 | SELECT * 3 | FROM Cinema 4 | WHERE description <> 'boring' AND id % 2 <> 0 5 | ORDER BY rating DESC; -------------------------------------------------------------------------------- /Golang/75-sort-colors/sort-colors.go: -------------------------------------------------------------------------------- 1 | func sortColors(nums []int) { 2 | zero, one, two := 0, 0, 0 3 | for _, num := range nums { 4 | if num == 0 { 5 | zero++ 6 | } else if num == 1 { 7 | one++ 8 | } else { 9 | two++ 10 | } 11 | } 12 | i := 0 13 | for zero > 0 { 14 | nums[i] = 0 15 | i++ 16 | zero-- 17 | } 18 | for one > 0 { 19 | nums[i] = 1 20 | i++ 21 | one-- 22 | } 23 | for two > 0 { 24 | nums[i] = 2 25 | i++ 26 | two-- 27 | } 28 | } -------------------------------------------------------------------------------- /Golang/88-merge-sorted-array/merge-sorted-array.go: -------------------------------------------------------------------------------- 1 | func merge(nums1 []int, m int, nums2 []int, n int) { 2 | // if m == 0 { 3 | // nums1 = nums2 4 | // } else if n == 0 { 5 | // return 6 | // } 7 | l := m + n - 1 8 | for n > 0 { 9 | if m > 0 && (nums1[m-1] >= nums2[n-1]) { 10 | nums1[l] = nums1[m-1] 11 | m-- 12 | l-- 13 | } else { 14 | nums1[l] = nums2[n-1] 15 | n-- 16 | l-- 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Golang/890-lemonade-change/lemonade-change.go: -------------------------------------------------------------------------------- 1 | func lemonadeChange(bills []int) bool { 2 | five, ten := 0, 0 3 | for _, bill := range bills { 4 | if bill == 5 { 5 | five++ 6 | } else if bill == 10 { 7 | if five > 0 { 8 | five-- 9 | ten++ 10 | } else { 11 | return false 12 | } 13 | } else { 14 | if five > 0 && ten > 0 { 15 | five-- 16 | ten-- 17 | } else if five > 2 { 18 | five -= 3 19 | } else { 20 | return false 21 | } 22 | } 23 | } 24 | return true 25 | } -------------------------------------------------------------------------------- /Golang/9-palindrome-number/palindrome-number.go: -------------------------------------------------------------------------------- 1 | func isPalindrome(x int) bool { 2 | if x < 0 { 3 | return false 4 | } 5 | if x < 10 { 6 | return true 7 | } 8 | temp := 0 9 | newNum := 0 10 | y := x 11 | for y > 0 { 12 | temp = y%10 13 | newNum = newNum*10 + temp 14 | y=y/10 15 | } 16 | if newNum == x { 17 | return true 18 | } 19 | return false 20 | } -------------------------------------------------------------------------------- /Golang/920-uncommon-words-from-two-sentences/uncommon-words-from-two-sentences.go: -------------------------------------------------------------------------------- 1 | func uncommonFromSentences(s1 string, s2 string) []string { 2 | str1, str2 := strings.Split(s1, " "), strings.Split(s2, " ") 3 | map1, map2 := make(map[string]int, len(str1)), make(map[string]int, len(str2)) 4 | output := make([]string, 0, len(str1)) 5 | for _, str := range str1 { 6 | map1[str]++ 7 | } 8 | for _, str := range str2 { 9 | map2[str]++ 10 | } 11 | for key, value := range map1 { 12 | if value == 1 { 13 | if _, exists := map2[key]; !exists { 14 | output = append(output, key) 15 | } 16 | } 17 | } 18 | for key, value := range map2 { 19 | if value == 1 { 20 | if _, exists := map1[key]; !exists { 21 | output = append(output, key) 22 | } 23 | } 24 | } 25 | return output 26 | } 27 | -------------------------------------------------------------------------------- /Golang/94-binary-tree-inorder-traversal/README.md: -------------------------------------------------------------------------------- 1 |

Binary Tree Inorder Traversal

Difficulty: Easy

Given the root of a binary tree, return the inorder traversal of its nodes' values.

2 | 3 |

 

4 |

Example 1:

5 | 6 |
 7 | Input: root = [1,null,2,3]
 8 | Output: [1,3,2]
 9 | 
10 | 11 |

Example 2:

12 | 13 |
14 | Input: root = []
15 | Output: []
16 | 
17 | 18 |

Example 3:

19 | 20 |
21 | Input: root = [1]
22 | Output: [1]
23 | 
24 | 25 |

 

26 |

Constraints:

27 | 28 |
    29 |
  • The number of nodes in the tree is in the range [0, 100].
  • 30 |
  • -100 <= Node.val <= 100
  • 31 |
32 | 33 |

 

34 | Follow up: Recursive solution is trivial, could you do it iteratively? -------------------------------------------------------------------------------- /Golang/94-binary-tree-inorder-traversal/binary-tree-inorder-traversal.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * type TreeNode struct { 4 | * Val int 5 | * Left *TreeNode 6 | * Right *TreeNode 7 | * } 8 | */ 9 | func inorderTraversal(root *TreeNode) []int { 10 | nums := []int{} 11 | if root == nil { 12 | return nums 13 | } 14 | nums = append(nums, inorderTraversal(root.Left)...) 15 | nums = append(nums, root.Val) 16 | nums = append(nums, inorderTraversal(root.Right)...) 17 | return nums 18 | } -------------------------------------------------------------------------------- /Golang/Leetccode 3028. Ant on the Boundary.go: -------------------------------------------------------------------------------- 1 | func returnToBoundaryCount(nums []int) int { 2 | currPos, count := 0, 0 3 | for _, val := range nums { 4 | currPos += val 5 | if currPos == 0 { 6 | count++ 7 | } 8 | } 9 | return count 10 | } 11 | -------------------------------------------------------------------------------- /Golang/Leetcode 344 Reverse String Golang Solution.go: -------------------------------------------------------------------------------- 1 | 2 | func reverseString(s []byte) { 3 | size := len(s) 4 | for i:=0; i < (size/2); i++ { 5 | s[i], s[size-i-1] = s[size-i-1], s[i] 6 | } 7 | return 8 | } 9 | -------------------------------------------------------------------------------- /Golang/Leetcode 1 Two Sum.go: -------------------------------------------------------------------------------- 1 | func twoSum(nums []int, target int) []int { 2 | numsMap := make(map[int]int) 3 | for i, num := range nums { 4 | if _, ok := numsMap[(target - num)]; ok { 5 | j := numsMap[(target - num)] 6 | return []int{i,j} 7 | } 8 | numsMap[num] = i 9 | } 10 | return []int{} 11 | } 12 | -------------------------------------------------------------------------------- /Golang/Leetcode 100 Same Tree.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * type TreeNode struct { 4 | * Val int 5 | * Left *TreeNode 6 | * Right *TreeNode 7 | * } 8 | */ 9 | // func inOrder(n *TreeNode) []int { 10 | // nums := []int{} 11 | // if n == nil { 12 | // return nums 13 | // } 14 | // nums = append(nums, inOrder(n.Left)...) 15 | // nums = append(nums, n.Val) 16 | // nums = append(nums, inOrder(n.Right)...) 17 | // return nums 18 | // } 19 | func isSameTree(p *TreeNode, q *TreeNode) bool { 20 | // pArray := inOrder(p) 21 | // qArray := inOrder(q) 22 | // if (reflect.DeepEqual(pArray,qArray)) { 23 | // return true 24 | // } else { 25 | // return false 26 | // } 27 | if p == nil && q == nil { 28 | return true 29 | } else if p == nil || q == nil { 30 | return false 31 | } 32 | if p.Val != q.Val { 33 | return false 34 | } 35 | return ( isSameTree(p.Left,q.Left) && isSameTree(p.Right,q.Right) ) 36 | return true 37 | } 38 | -------------------------------------------------------------------------------- /Golang/Leetcode 104 Maximum Depth of Binary Tree.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * type TreeNode struct { 4 | * Val int 5 | * Left *TreeNode 6 | * Right *TreeNode 7 | * } 8 | */ 9 | func maxDepth(root *TreeNode) int { 10 | if root == nil { 11 | return 0 12 | } 13 | return max(maxDepth(root.Left),maxDepth(root.Right)) + 1 14 | } 15 | func max(x,y int) int { 16 | if x > y { 17 | return x 18 | } else { 19 | return y 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Golang/Leetcode 1089. Duplicate Zeros.go: -------------------------------------------------------------------------------- 1 | func duplicateZeros(arr []int) { 2 | leng := len(arr) - 1 3 | for i := 0; i < len(arr)-1; i++ { 4 | if arr[i] == 0 { 5 | for j := leng; j > i; j-- { 6 | arr[j] = arr[j-1] 7 | } 8 | arr[i+1] = 0 9 | i = i + 1 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Golang/Leetcode 1108 Defanging an IP Address Golang Solution.go: -------------------------------------------------------------------------------- 1 | func defangIPaddr(address string) string { 2 | return (strings.Replace(address, ".", "[.]", -1)) 3 | } 4 | -------------------------------------------------------------------------------- /Golang/Leetcode 1207. Unique Number of Occurrences.go: -------------------------------------------------------------------------------- 1 | func uniqueOccurrences(arr []int) bool { 2 | numsMap := make(map[int]int) 3 | 4 | // Count occurrences of each value 5 | for _, num := range arr { 6 | numsMap[num]++ 7 | } 8 | 9 | // Check for unique frequencies 10 | freqMap := make(map[int]bool) 11 | for _, val := range numsMap { 12 | if freqMap[val] { 13 | return false 14 | } 15 | freqMap[val] = true 16 | } 17 | return true 18 | } 19 | -------------------------------------------------------------------------------- /Golang/Leetcode 121. Best Time to Buy and Sell Stock.go: -------------------------------------------------------------------------------- 1 | func maxProfit(prices []int) int { 2 | maxProfit := 0 3 | minStock := prices[0] 4 | for i := 1; i < len(prices); i++ { 5 | if prices[i] < minStock { 6 | minStock = prices[i] 7 | } else if (prices[i] - minStock) > maxProfit { 8 | maxProfit = prices[i] - minStock 9 | } 10 | } 11 | return maxProfit 12 | } 13 | -------------------------------------------------------------------------------- /Golang/Leetcode 1281 Subtract the Product and Sum of Digits of an Integer.go: -------------------------------------------------------------------------------- 1 | func subtractProductAndSum(n int) int { 2 | product, sum := 1, 0 3 | for n > 0 { 4 | sum += n % 10 5 | product *= n % 10 6 | n /= 10 7 | } 8 | return (product - sum) 9 | } 10 | -------------------------------------------------------------------------------- /Golang/Leetcode 1282 Group the People Given the Group Size They Belong To.go: -------------------------------------------------------------------------------- 1 | func groupThePeople(groupSizes []int) [][]int { 2 | numMap := make(map[int][]int) 3 | result := [][]int{} 4 | for i, num := range groupSizes { 5 | numMap[num] = append(numMap[num],i) 6 | if len(numMap[num]) == num { 7 | result = append(result,numMap[num]) 8 | numMap[num] = []int{} 9 | } 10 | } 11 | return result 12 | } 13 | -------------------------------------------------------------------------------- /Golang/Leetcode 1290 Convert Binary Number in a Linked List to Integer.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * type ListNode struct { 4 | * Val int 5 | * Next *ListNode 6 | * } 7 | */ 8 | func getDecimalValue(head *ListNode) int { 9 | num := 0 10 | for (head != nil){ 11 | num = num * 2 + head.Val 12 | head = head.Next 13 | } 14 | return num 15 | } 16 | -------------------------------------------------------------------------------- /Golang/Leetcode 1291. Sequential Digits.go: -------------------------------------------------------------------------------- 1 | //Not the good approach 2 | func sequentialDigits(low int, high int) []int { 3 | nums := []int{} 4 | sequence := []int{ 5 | 12,23,34,45,56,67,78,89, 6 | 123,234,345,456,567,678,789, 7 | 1234,2345,3456,4567,5678,6789, 8 | 12345,23456,34567,45678,56789, 9 | 123456,234567,345678,456789, 10 | 1234567,2345678,3456789, 11 | 12345678,23456789,123456789} 12 | for _, num := range sequence { 13 | if num > high { 14 | break 15 | } else if num >= low { 16 | nums = append(nums,num) 17 | } 18 | } 19 | return nums 20 | } 21 | -------------------------------------------------------------------------------- /Golang/Leetcode 1302. Deepest Leaves Sum.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * type TreeNode struct { 4 | * Val int 5 | * Left *TreeNode 6 | * Right *TreeNode 7 | * } 8 | */ 9 | func deepestLeavesSum(root *TreeNode) int { 10 | depth := maxDepth(root) 11 | return sum(root, 1, depth) 12 | } 13 | func maxDepth(root *TreeNode) int { 14 | if root == nil { return 0 } 15 | left := maxDepth(root.Left) 16 | right := maxDepth(root.Right) 17 | if left > right { return left + 1 } 18 | return right + 1 19 | } 20 | func sum(root *TreeNode, current int, depth int) int { 21 | if root == nil { return 0 } 22 | if current == depth { return root.Val } 23 | left := sum(root.Left, current+1, depth) 24 | right := sum(root.Right, current+1, depth) 25 | return left + right 26 | } 27 | -------------------------------------------------------------------------------- /Golang/Leetcode 1304 Find N Unique Integers Sum up to Zero.go: -------------------------------------------------------------------------------- 1 | func sumZero(n int) []int { 2 | var resultArray []int 3 | if(n%2==1){ 4 | resultArray = append(resultArray,0) 5 | } 6 | for i:=1;i<=(n/2);i++ { 7 | resultArray = append(resultArray,i,-i) 8 | } 9 | return resultArray 10 | } 11 | -------------------------------------------------------------------------------- /Golang/Leetcode 1313. Decompress Run-Length Encoded List.go: -------------------------------------------------------------------------------- 1 | func decompressRLElist(nums []int) []int { 2 | arr := []int{} 3 | for i:=0; i 0 { 6 | if a % 10 == 0 { 7 | flag = 1 8 | break 9 | } 10 | a /= 10 11 | } 12 | if flag == 0 { 13 | for b > 0 { 14 | if b % 10 == 0 { 15 | flag = 1 16 | break 17 | } 18 | b /= 10 19 | } 20 | } 21 | if flag == 0 { 22 | return []int{i, n-i} 23 | } 24 | } 25 | return []int{a, b} 26 | } 27 | -------------------------------------------------------------------------------- /Golang/Leetcode 1347. Minimum Number of Steps to Make Two Strings Anagram.go: -------------------------------------------------------------------------------- 1 | func minSteps(s string, t string) int { 2 | diff := 0 3 | sMap := make(map[byte]int) 4 | tMap := make(map[byte]int) 5 | for i, _ := range s { 6 | sMap[s[i]]++ 7 | tMap[t[i]]-- 8 | } 9 | for key, value := range sMap { 10 | if value > tMap[key] { 11 | diff += value - tMap[key] 12 | } 13 | } 14 | return diff 15 | } 16 | -------------------------------------------------------------------------------- /Golang/Leetcode 1351. Count Negative Numbers in a Sorted Matrix.go: -------------------------------------------------------------------------------- 1 | func countNegatives(grid [][]int) int { 2 | count:=0 3 | m, n := len(grid), len(grid[0]) 4 | for i:=0;i nums[j] { 7 | count++ 8 | } 9 | } 10 | returnArray = append(returnArray,count) 11 | } 12 | return returnArray 13 | } 14 | -------------------------------------------------------------------------------- /Golang/Leetcode 1370 Increasing Decreasing String.go: -------------------------------------------------------------------------------- 1 | func sortString(s string) string { 2 | charMap := make(map[rune]int) 3 | outputString := make([]rune, 0, len(s)) 4 | for _, char := range s { 5 | charMap[char]++ 6 | } 7 | for len(outputString) < len(s) { 8 | for char := 'a'; char <= 'z'; char++ { 9 | if charMap[char] > 0 { 10 | outputString = append(outputString, char) 11 | charMap[char]-- 12 | } 13 | } 14 | for char := 'z'; char >= 'a'; char-- { 15 | if charMap[char] > 0 { 16 | outputString = append(outputString, char) 17 | charMap[char]-- 18 | } 19 | } 20 | } 21 | return string(outputString) 22 | } 23 | -------------------------------------------------------------------------------- /Golang/Leetcode 1385. Find the Distance Value Between Two Arrays.go: -------------------------------------------------------------------------------- 1 | func findTheDistanceValue(arr1 []int, arr2 []int, d int) int { 2 | count := 0 3 | for i:=0; i large { 5 | large = candies[i] 6 | } 7 | } 8 | boolArray := make([]bool,len(candies),len(candies)) 9 | for i, candy := range candies { 10 | boolArray[i] = candy+extraCandies >= large 11 | } 12 | return boolArray 13 | } 14 | -------------------------------------------------------------------------------- /Golang/Leetcode 144 Binary Tree Preorder Traversal.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * type TreeNode struct { 4 | * Val int 5 | * Left *TreeNode 6 | * Right *TreeNode 7 | * } 8 | */ 9 | func preorderTraversal(root *TreeNode) []int { 10 | nums := []int{} 11 | if root == nil { 12 | return nums 13 | } 14 | nums = append(nums, root.Val) 15 | nums = append(nums, preorderTraversal(root.Left)...) 16 | nums = append(nums, preorderTraversal(root.Right)...) 17 | return nums 18 | } 19 | -------------------------------------------------------------------------------- /Golang/Leetcode 145 Binary Tree Postorder Traversal.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * type TreeNode struct { 4 | * Val int 5 | * Left *TreeNode 6 | * Right *TreeNode 7 | * } 8 | */ 9 | func postorderTraversal(root *TreeNode) []int { 10 | nums := []int{} 11 | if root == nil { 12 | return nums 13 | } 14 | nums = append(nums, postorderTraversal(root.Left)...) 15 | nums = append(nums, postorderTraversal(root.Right)...) 16 | nums = append(nums, root.Val) 17 | return nums 18 | } 19 | -------------------------------------------------------------------------------- /Golang/Leetcode 1450. Number of Students Doing Homework at a Given Time Golang Solution.go: -------------------------------------------------------------------------------- 1 | func busyStudent(startTime []int, endTime []int, queryTime int) int { 2 | count := 0 3 | for i:=0; i=queryTime { 5 | count++ 6 | } 7 | } 8 | return count 9 | } 10 | -------------------------------------------------------------------------------- /Golang/Leetcode 1470 Shuffle the Array Golang Solution.go: -------------------------------------------------------------------------------- 1 | //Leetcode 1470 Shuffle the Array Golang Solution.go 2 | func shuffle(nums []int, n int) []int { 3 | newArray := []int{} 4 | for i:=0; i0; i++ { 13 | remove := i * freqArr[i] 14 | if k >= remove { 15 | k -= remove 16 | l -= freqArr[i] 17 | } else { 18 | l -= (k / i) 19 | return l 20 | } 21 | } 22 | return l 23 | } 24 | -------------------------------------------------------------------------------- /Golang/Leetcode 1486 XOR Operation in an Array Golang Solution.go: -------------------------------------------------------------------------------- 1 | func xorOperation(n int, start int) int { 2 | answer := 0 3 | for i:=0; i0; i-=3 { 28 | numString = numString[:i]+"."+numString[i:] 29 | } 30 | return numString 31 | } 32 | -------------------------------------------------------------------------------- /Golang/Leetcode 1588 Sum of All Odd Length Subarrays.go: -------------------------------------------------------------------------------- 1 | func sumOddLengthSubarrays(arr []int) int { 2 | sum := 0 3 | l := len(arr) 4 | for i:=0; i countB { 21 | for i:=0; i<(countA-countB); i++ { 22 | listA = listA.Next 23 | } 24 | } else { 25 | for i:=0; i<(countB-countA); i++ { 26 | listB = listB.Next 27 | } 28 | } 29 | for listA != nil && listB != nil { 30 | if listB == listA { 31 | return listB 32 | } 33 | listA = listA.Next 34 | listB = listB.Next 35 | } 36 | return nil 37 | } 38 | -------------------------------------------------------------------------------- /Golang/Leetcode 1614. Maximum Nesting Depth of the Parentheses.go: -------------------------------------------------------------------------------- 1 | func maxDepth(s string) int { 2 | depth, maxdepth := 0, 0 3 | for i:=0; i maxdepth { 10 | maxdepth = depth 11 | } 12 | } 13 | return maxdepth 14 | } 15 | -------------------------------------------------------------------------------- /Golang/Leetcode 1624 Largest Substring Between Two Equal Characters.go: -------------------------------------------------------------------------------- 1 | func maxLengthBetweenEqualCharacters(s string) int { 2 | maxLength := -1 3 | arrMap := make(map[rune]int) 4 | for idx, char := range s { 5 | if j, ok := arrMap[char]; ok { 6 | if (idx - j - 1) > maxLength { 7 | maxLength = idx - j - 1 8 | } 9 | } else { 10 | arrMap[char] = idx 11 | } 12 | } 13 | return maxLength 14 | } 15 | -------------------------------------------------------------------------------- /Golang/Leetcode 1657. Determine if Two Strings Are Close.go: -------------------------------------------------------------------------------- 1 | func closeStrings(word1 string, word2 string) bool { 2 | if len(word1) != len(word2) { 3 | return false 4 | } 5 | word1Map := make(map[byte]int) 6 | word2Map := make(map[byte]int) 7 | word1Array, word2Array := []int{}, []int{} 8 | for i, _ := range word1 { 9 | word1Map[word1[i]]++ 10 | } 11 | for i, _ := range word2 { 12 | word2Map[word2[i]]++ 13 | if word1Map[word2[i]] < 1 { 14 | return false 15 | } 16 | } 17 | for _, value := range word1Map { 18 | word1Array = append(word1Array, value) 19 | } 20 | for _, value := range word2Map { 21 | word2Array = append(word2Array, value) 22 | } 23 | sort.Ints(word1Array) 24 | sort.Ints(word2Array) 25 | // if !reflect.DeepEqual(word1Array, word2Array) { 26 | // return false 27 | // } 28 | for i:=0; i max { 9 | max = sum 10 | } 11 | } 12 | return max 13 | } 14 | -------------------------------------------------------------------------------- /Golang/Leetcode 1678 Goal Parser Interpretation.go: -------------------------------------------------------------------------------- 1 | func interpret(command string) string { 2 | output := "" 3 | for i:=0; i 1 { 4 | matches += n / 2 5 | if n % 2 == 0 { 6 | n = n / 2 7 | } else { 8 | n = (n - 1) / 2 + 1 9 | } 10 | } 11 | return matches 12 | } 13 | 14 | //func numberOfMatches(n int) int { 15 | // return n-1 16 | // } 17 | -------------------------------------------------------------------------------- /Golang/Leetcode 1689 Partitioning Into Minimum Number Of Deci-Binary Numbers.go: -------------------------------------------------------------------------------- 1 | func minPartitions(n string) int { 2 | large := n[0] 3 | for i:=1; i large { 10 | large = value 11 | num = index 12 | } 13 | } 14 | return num 15 | } 16 | -------------------------------------------------------------------------------- /Golang/Leetcode 1704. Determine if String Halves Are Alike.go: -------------------------------------------------------------------------------- 1 | func halvesAreAlike(s string) bool { 2 | count := 0 3 | for i, char := range s { 4 | if char == 'a' || char == 'e' || char == 'i' || char == 'o' || char == 'u' || char == 'A' || char == 'E' || char == 'I' || char == 'O' || char == 'U' { 5 | if i < len(s)/2 { 6 | count++ 7 | } else { 8 | count-- 9 | } 10 | } 11 | } 12 | return count == 0 13 | } 14 | -------------------------------------------------------------------------------- /Golang/Leetcode 1710. Maximum Units on a Truck.go: -------------------------------------------------------------------------------- 1 | func maximumUnits(boxTypes [][]int, truckSize int) int { 2 | output := 0 3 | sort.Slice(boxTypes, func(i, j int) bool { 4 | return boxTypes[i][1] > boxTypes[j][1] 5 | }) 6 | for i:=0; i= boxTypes[i][0] { 8 | output += boxTypes[i][0] * boxTypes[i][1] 9 | truckSize -= boxTypes[i][0] 10 | } else { 11 | output += truckSize * boxTypes[i][1] 12 | return output 13 | } 14 | } 15 | return output 16 | } 17 | -------------------------------------------------------------------------------- /Golang/Leetcode 1720. Decode XORed Array.go: -------------------------------------------------------------------------------- 1 | func decode(encoded []int, first int) []int { 2 | arr := make([]int, len(encoded)+1) 3 | arr[0] = first 4 | for i:=0; i 3 { 11 | return false 12 | } 13 | } 14 | return count == 3 15 | } 16 | -------------------------------------------------------------------------------- /Golang/Leetcode 1979. Find Greatest Common Divisor of Array.go: -------------------------------------------------------------------------------- 1 | func findGCD(nums []int) int { 2 | small, large := 0, 0 3 | if nums[0] > nums[1] { 4 | small, large = nums[1], nums[0] 5 | } else { 6 | small, large = nums[0], nums[1] 7 | } 8 | for i:=0; i large { 13 | large = nums[i] 14 | } 15 | } 16 | for i:=small; i>0; i-- { 17 | if small % i == 0 && large % i == 0 { 18 | return i 19 | } 20 | } 21 | return 1 22 | } 23 | -------------------------------------------------------------------------------- /Golang/Leetcode 20 Valid Parentheses.go: -------------------------------------------------------------------------------- 1 | //Using maps 2 | func isValid(s string) bool { 3 | sStack := []rune{} 4 | sMap := map[rune]rune { 5 | ')':'(', 6 | ']':'[', 7 | '}':'{', 8 | } 9 | for _, ch := range s { 10 | if ch == '{' || ch == '(' || ch == '[' { 11 | sStack = append(sStack, ch) 12 | } else if ch == '}' || ch == ')' || ch == ']' { 13 | if len(sStack) == 0 || sMap[ch] != sStack[len(sStack)-1] { 14 | return false 15 | } 16 | sStack = sStack[:len(sStack)-1] 17 | } 18 | } 19 | return len(sStack) == 0 20 | } 21 | 22 | func isValid(s string) bool { 23 | // if len(s) % 2 != 0 { 24 | // return false 25 | // } 26 | stack := []rune{} 27 | for _, ch := range s { 28 | if ch == '(' || ch == '{' || ch == '[' { 29 | stack = append(stack,ch) 30 | } else if ch == '}' && len(stack) > 0 && stack[len(stack)-1] == '{' { 31 | stack = stack[:len(stack)-1] 32 | } else if ch == ']' && len(stack) > 0 && stack[len(stack)-1] == '[' { 33 | stack = stack[:len(stack)-1] 34 | } else if ch == ')' && len(stack) > 0 && stack[len(stack)-1] == '(' { 35 | stack = stack[:len(stack)-1] 36 | } else { 37 | return false 38 | } 39 | } 40 | return len(stack) == 0 41 | } 42 | -------------------------------------------------------------------------------- /Golang/Leetcode 2006 Count Number of Pairs With Absolute Difference K.go: -------------------------------------------------------------------------------- 1 | func countKDifference(nums []int, k int) int { 2 | count := 0 3 | for i:=0; i 0{ 18 | sum += (num % 10) * (num % 10) 19 | num /= 10 20 | } 21 | return sum 22 | } 23 | -------------------------------------------------------------------------------- /Golang/Leetcode 205 Isomorphic Strings.go: -------------------------------------------------------------------------------- 1 | func isIsomorphic(s string, t string) bool { 2 | sMap := make(map[byte]int) 3 | tMap := make(map[byte]int) 4 | for i := range s { 5 | if sMap[s[i]] != tMap[t[i]] { 6 | return false 7 | } else { 8 | sMap[s[i]] = i+1 9 | tMap[t[i]] = i+1 10 | } 11 | } 12 | return true 13 | } 14 | -------------------------------------------------------------------------------- /Golang/Leetcode 206. Reverse Linked List.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * type ListNode struct { 4 | * Val int 5 | * Next *ListNode 6 | * } 7 | */ 8 | func reverseList(head *ListNode) *ListNode { 9 | if head == nil || head.Next == nil { 10 | return head 11 | } 12 | var revHead *ListNode 13 | for head != nil { 14 | tmp := head.Next 15 | head.Next = revHead 16 | revHead = head 17 | head = tmp 18 | } 19 | return revHead 20 | } 21 | -------------------------------------------------------------------------------- /Golang/Leetcode 2089 Find Target Indices After Sorting Array.go: -------------------------------------------------------------------------------- 1 | func targetIndices(nums []int, target int) []int { 2 | sort.Ints(nums) 3 | output := []int{} 4 | for idx, val := range nums { 5 | if val == target { 6 | output = append(output, idx) 7 | } 8 | } 9 | return output 10 | } 11 | -------------------------------------------------------------------------------- /Golang/Leetcode 2095 Delete the Middle Node of a Linked List.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * type ListNode struct { 4 | * Val int 5 | * Next *ListNode 6 | * } 7 | */ 8 | func deleteMiddle(head *ListNode) *ListNode { 9 | if head == nil || head.Next == nil { 10 | return nil 11 | } 12 | slow, fast := head, head.Next.Next 13 | for fast != nil && fast.Next != nil { 14 | slow = slow.Next 15 | fast = fast.Next.Next 16 | } 17 | slow.Next = slow.Next.Next 18 | return head 19 | } 20 | -------------------------------------------------------------------------------- /Golang/Leetcode 2108. Find First Palindromic String in the Array.go: -------------------------------------------------------------------------------- 1 | func firstPalindrome(words []string) string { 2 | for _, word := range words { 3 | if checkPalindrome(word) { 4 | return word 5 | } 6 | } 7 | return "" 8 | } 9 | func checkPalindrome(word string) bool { 10 | l := len(word) 11 | for i:=0; i max { 11 | max = space+1 12 | } 13 | } 14 | return max 15 | } 16 | -------------------------------------------------------------------------------- /Golang/Leetcode 2119 A Number After a Double Reversal.go: -------------------------------------------------------------------------------- 1 | func isSameAfterReversals(num int) bool { 2 | if (num % 10 == 0 && num > 0) { 3 | return false 4 | } else { 5 | return true 6 | } 7 | return true 8 | } 9 | -------------------------------------------------------------------------------- /Golang/Leetcode 2124 Check if All A's Appears Before All B's.go: -------------------------------------------------------------------------------- 1 | func checkString(s string) bool { 2 | for i, ch := range s { 3 | if ch == 'b' { 4 | if i == len(s)-1 { 5 | break 6 | }else if s[i+1] == 'a' { 7 | return false 8 | } 9 | } 10 | } 11 | return true 12 | } 13 | -------------------------------------------------------------------------------- /Golang/Leetcode 2125 Number of Laser Beams in a Bank.go: -------------------------------------------------------------------------------- 1 | func numberOfBeams(bank []string) int { 2 | laserCount, prev := 0, 0 3 | rLength, cLength := len(bank), len((bank[0])) 4 | for row := 0; row < rLength; row++ { 5 | count := 0 6 | for col := 0; col < cLength; col++ { 7 | if bank[row][col] == '1' { 8 | count++ 9 | } 10 | } 11 | if count > 0 { 12 | laserCount += prev * count 13 | prev = count 14 | } 15 | } 16 | return laserCount 17 | } 18 | -------------------------------------------------------------------------------- /Golang/Leetcode 2154. Keep Multiplying Found Values by Two.go: -------------------------------------------------------------------------------- 1 | func findFinalValue(nums []int, original int) int { 2 | numsMap := make(map[int]bool) 3 | for _, num := range nums { 4 | if num % original == 0 { 5 | numsMap[num] = true 6 | } 7 | } 8 | for numsMap[original] { 9 | original *= 2 10 | } 11 | return original 12 | } 13 | -------------------------------------------------------------------------------- /Golang/Leetcode 217 Contains Duplicate.go: -------------------------------------------------------------------------------- 1 | func containsDuplicate(nums []int) bool { 2 | numMap := make(map[int]bool) 3 | for _, num := range nums { 4 | if numMap[num] { 5 | return true 6 | } 7 | numMap[num] = true 8 | } 9 | return false 10 | } 11 | -------------------------------------------------------------------------------- /Golang/Leetcode 2176 Count Equal and Divisible Pairs in an Array.go: -------------------------------------------------------------------------------- 1 | func countPairs(nums []int, k int) int { 2 | count := 0 3 | for i:=0; i 10 { 7 | j := i 8 | digitSum := 0 9 | for j>0 { 10 | digitSum += j % 10 11 | j = j / 10 12 | } 13 | if digitSum % 2 == 0 { 14 | count++ 15 | } 16 | } 17 | } 18 | return count 19 | } 20 | -------------------------------------------------------------------------------- /Golang/Leetcode 2186. Minimum Number of Steps to Make Two Strings Anagram II.go: -------------------------------------------------------------------------------- 1 | func minSteps(s string, t string) int { 2 | diff := 0 3 | stMap := make(map[byte]int) 4 | //sMap := make(map[byte]int) 5 | //tMap := make(map[byte]int) 6 | for i, _ := range s { 7 | stMap[s[i]]++ 8 | } 9 | for i, _ := range t { 10 | stMap[t[i]]-- 11 | } 12 | for _, value := range stMap { 13 | if value > 0 { 14 | diff += value 15 | } else { 16 | diff -= value 17 | } 18 | } 19 | // for key, value := range sMap { 20 | // if value > tMap[key] { 21 | // diff += value - tMap[key] 22 | // } 23 | // } 24 | // for key, value := range tMap { 25 | // if value > sMap[key] { 26 | // diff += value - sMap[key] 27 | // } 28 | // } 29 | return diff 30 | } 31 | -------------------------------------------------------------------------------- /Golang/Leetcode 219. Contains Duplicate II.go: -------------------------------------------------------------------------------- 1 | func containsNearbyDuplicate(nums []int, k int) bool { 2 | // for i:=len(nums)-1; i>0; i-- { 3 | // for j:=i-1; j>=0; j-- { 4 | // if nums[i] == nums[j] && (i-j) <= k { 5 | // return true 6 | // } 7 | // } 8 | // } 9 | // return false 10 | 11 | 12 | // numsMap := make(map[int][]int) 13 | // for idx, val := range nums { 14 | // numsMap[val] = append(numsMap[val], idx) 15 | // } 16 | // for _, arr := range numsMap { 17 | // if len(arr) > 1 { 18 | // for i:=len(arr)-1; i>0; i-- { 19 | // if (arr[i] - arr[i-1]) <= k { 20 | // return true 21 | // } 22 | // } 23 | // } 24 | // } 25 | // return false 26 | 27 | 28 | numsMap := make(map[int]int) 29 | for i:=len(nums)-1; i>=0; i-- { 30 | val, exists := numsMap[nums[i]] 31 | if exists && (val - i) <= k { 32 | return true 33 | } 34 | numsMap[(nums[i])] = i 35 | } 36 | //fmt.Println(numsMap) 37 | return false 38 | } 39 | -------------------------------------------------------------------------------- /Golang/Leetcode 2190. Most Frequent Number Following Key In an Array.go: -------------------------------------------------------------------------------- 1 | func mostFrequent(nums []int, key int) int { 2 | numsMap := make(map[int]int) 3 | maxCount, res := 0, 0 4 | for i:=0; i < len(nums)-1; i++ { 5 | if nums[i] == key { 6 | numsMap[nums[i+1]]++ 7 | if numsMap[nums[i+1]] > maxCount { 8 | maxCount = numsMap[nums[i+1]] 9 | res = nums[i+1] 10 | } 11 | } 12 | } 13 | fmt.Println(numsMap) 14 | return res 15 | } 16 | -------------------------------------------------------------------------------- /Golang/Leetcode 2215. Find the Difference of Two Arrays.go: -------------------------------------------------------------------------------- 1 | func findDifference(nums1 []int, nums2 []int) [][]int { 2 | nums1Map := make(map[int]bool) 3 | nums2Map := make(map[int]bool) 4 | arr := [][]int{{},{}} 5 | for _, num := range nums1 { 6 | nums1Map[num] = true 7 | } 8 | for _, num := range nums2 { 9 | nums2Map[num] = true 10 | } 11 | for key, _ := range nums1Map { 12 | if !nums2Map[key] { 13 | arr[0] = append(arr[0],key) 14 | } 15 | } 16 | for key, _ := range nums2Map { 17 | if !nums1Map[key] { 18 | arr[1] = append(arr[1],key) 19 | } 20 | } 21 | return arr 22 | } 23 | -------------------------------------------------------------------------------- /Golang/Leetcode 2235 Add Two Integers.go: -------------------------------------------------------------------------------- 1 | func sum(num1 int, num2 int) int { 2 | return num1+num2 3 | } 4 | -------------------------------------------------------------------------------- /Golang/Leetcode 2273. Find Resultant Array After Removing Anagrams.go: -------------------------------------------------------------------------------- 1 | func removeAnagrams(words []string) []string { 2 | output := []string{} 3 | for i:=len(words)-1; i>0; i-- { 4 | if !anagram(words[i], words[i-1]) { 5 | output = append(output, words[i]) 6 | } 7 | } 8 | output = append(output, words[0]) 9 | length := len(output) 10 | for i:=0; i 0 { 10 | if n/2 == 1 && n % 2 == 0 { 11 | return true 12 | } else if n % 2 == 1{ 13 | return false 14 | } 15 | n = n / 2 16 | } 17 | return false 18 | } 19 | -------------------------------------------------------------------------------- /Golang/Leetcode 234. Palindrome Linked List.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * type ListNode struct { 4 | * Val int 5 | * Next *ListNode 6 | * } 7 | */ 8 | func isPalindrome(head *ListNode) bool { 9 | values := []int{} 10 | for head != nil { 11 | values = append(values, head.Val) 12 | head = head.Next 13 | } 14 | size := len(values) 15 | //fmt.Println("Values : ", values, "\nSize : ", size) 16 | for i:=0; i 0 { 12 | baseNum += string(num % base) 13 | num = num / base 14 | } 15 | return palindrome(baseNum) 16 | } 17 | func palindrome(num string) bool { 18 | for i,j :=0, len(num)-1; i<=j; i,j = i+1, j-1 { 19 | if num[i] != num[j] { 20 | return false 21 | } 22 | } 23 | return true 24 | } 25 | -------------------------------------------------------------------------------- /Golang/Leetcode 2404. Most Frequent Even Element.go: -------------------------------------------------------------------------------- 1 | func mostFrequentEven(nums []int) int { 2 | numsMap := make(map[int]int) 3 | for _, num := range nums { 4 | if num % 2 == 0 { 5 | numsMap[num]++ 6 | } 7 | } 8 | evenElement := -1 9 | count := 0 10 | for key, val := range numsMap { 11 | if val > count || (val == count && key < evenElement) { 12 | count = val 13 | evenElement = key 14 | } 15 | } 16 | return evenElement 17 | } 18 | -------------------------------------------------------------------------------- /Golang/Leetcode 2413 Smallest Even Multiple.go: -------------------------------------------------------------------------------- 1 | func smallestEvenMultiple(n int) int { 2 | if n % 2 == 0 { 3 | return n 4 | } else { 5 | return n * 2 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Golang/Leetcode 242 Valid Anagram.go: -------------------------------------------------------------------------------- 1 | func isAnagram(s string, t string) bool { 2 | if len(s) != len(t) { 3 | return false 4 | } 5 | if s == t { 6 | return true 7 | } 8 | charMap := make(map[rune]int) 9 | for _,ch := range s { 10 | charMap[ch]++ 11 | } 12 | for _,ch := range t { 13 | charMap[ch]-- 14 | if (charMap[ch] < 0 ) { 15 | return false 16 | } 17 | } 18 | return true 19 | } 20 | -------------------------------------------------------------------------------- /Golang/Leetcode 2427 Number of Common Factors.go: -------------------------------------------------------------------------------- 1 | func commonFactors(a int, b int) int { 2 | factors := 1 3 | secondLarge := 0 4 | if a > b { 5 | secondLarge = b 6 | } else { 7 | secondLarge = a 8 | } 9 | for i:=2; i <= secondLarge; i++ { 10 | if a % i == 0 && b % i == 0 { 11 | factors++ 12 | } 13 | } 14 | return factors 15 | } 16 | -------------------------------------------------------------------------------- /Golang/Leetcode 2433 Find The Original Array of Prefix Xor.go: -------------------------------------------------------------------------------- 1 | func findArray(pref []int) []int { 2 | result := make([]int, len(pref)) 3 | result[0] = pref[0] 4 | for i:= 1; i < len(pref); i++ { 5 | result[i] = pref[i-1] ^ pref[i] 6 | } 7 | return result 8 | } 9 | -------------------------------------------------------------------------------- /Golang/Leetcode 2441 Largest Positive Integer That Exists With Its Negative.go: -------------------------------------------------------------------------------- 1 | func findMaxK(nums []int) int { 2 | numsMap := make(map[int]int) 3 | sort.Ints(nums) 4 | for _, num := range nums { 5 | numsMap[num]++ 6 | } 7 | for i:=len(nums)-1; i>0; i-- { 8 | if _, ok := numsMap[-nums[i]]; ok { 9 | return nums[i] 10 | } 11 | } 12 | return -1 13 | } 14 | -------------------------------------------------------------------------------- /Golang/Leetcode 2455. Average Value of Even Numbers That Are Divisible by Three.go: -------------------------------------------------------------------------------- 1 | func averageValue(nums []int) int { 2 | count, sum := 0, 0 3 | for _, num := range nums { 4 | if num % 6 == 0 { 5 | sum += num 6 | count++ 7 | } 8 | } 9 | if count == 0 { 10 | return 0 11 | } 12 | return sum/count 13 | } 14 | -------------------------------------------------------------------------------- /Golang/Leetcode 2469 Convert the Temperature Golang Solution.go: -------------------------------------------------------------------------------- 1 | func convertTemperature(celsius float64) []float64 { 2 | kelvin := celsius + 273.15 3 | fahrenheit := celsius * 1.80 + 32.00 4 | arr := []float64{kelvin,fahrenheit} 5 | return arr 6 | } 7 | -------------------------------------------------------------------------------- /Golang/Leetcode 2475 Number of Unequal Triplets in Array.go: -------------------------------------------------------------------------------- 1 | func unequalTriplets(nums []int) int { 2 | tripletCount := 0 3 | for i:=0; i maxVal { 9 | maxVal = val 10 | } 11 | } 12 | return maxVal 13 | } 14 | -------------------------------------------------------------------------------- /Golang/Leetcode 2535 Difference Between Element Sum and Digit Sum of an Array.go: -------------------------------------------------------------------------------- 1 | func differenceOfSum(nums []int) int { 2 | elementSum := 0 3 | digitSum := 0 4 | for _,value := range nums { 5 | elementSum += value 6 | for value>=1 { 7 | digitSum = digitSum + value%10 8 | value /= 10 9 | } 10 | } 11 | return((elementSum - digitSum)) 12 | } 13 | -------------------------------------------------------------------------------- /Golang/Leetcode 2540. Minimum Common Value.go: -------------------------------------------------------------------------------- 1 | func getCommon(nums1 []int, nums2 []int) int { 2 | for i,j := 0, 0; i 0 { 8 | sum += sign * (n % 10) 9 | n /= 10 10 | sign *= -1 11 | } 12 | return sum 13 | } 14 | -------------------------------------------------------------------------------- /Golang/Leetcode 2574. Left and Right Sum Differences.go: -------------------------------------------------------------------------------- 1 | func leftRightDifference(nums []int) []int { 2 | l := len(nums) 3 | if l == 1{ 4 | return []int{0} 5 | } 6 | sum := make([]int, l) 7 | leftRightSum := make([][2]int, l) 8 | leftRightSum[0][0] = 0 9 | leftRightSum[l-1][1] = 0 10 | for i:=1; i=0; i-- { 14 | leftRightSum[i][1] = leftRightSum[i+1][1] + nums[i+1] 15 | } 16 | for i:=0; i=0; i-- { 6 | if hours[i] >= target { 7 | count++ 8 | } 9 | } 10 | return count 11 | } 12 | -------------------------------------------------------------------------------- /Golang/Leetcode 28 Find the Index of the First Occurrence in a String.go: -------------------------------------------------------------------------------- 1 | func strStr(haystack string, needle string) int { 2 | return strings.Index(haystack, needle) 3 | } 4 | -------------------------------------------------------------------------------- /Golang/Leetcode 2807 Insert Greatest Common Divisors in Linked List.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * type ListNode struct { 4 | * Val int 5 | * Next *ListNode 6 | * } 7 | */ 8 | func insertGreatestCommonDivisors(head *ListNode) *ListNode { 9 | curr := head 10 | for curr != nil && curr.Next != nil { 11 | num := gcd(curr.Val, curr.Next.Val) 12 | newNode := &ListNode{ 13 | Val: num, 14 | Next: curr.Next, 15 | } 16 | curr.Next = newNode 17 | curr = curr.Next.Next 18 | } 19 | return head 20 | } 21 | 22 | func gcd(a, b int) int { 23 | if b == 0 { 24 | return a 25 | } 26 | tmp := a 27 | a = b 28 | b = tmp % a 29 | return gcd(a, b) 30 | } 31 | -------------------------------------------------------------------------------- /Golang/Leetcode 2824 Count Pairs Whose Sum is Less than Target.go: -------------------------------------------------------------------------------- 1 | func countPairs(nums []int, target int) int { 2 | count := 0 3 | for i:=0; i<(len(nums)-1); i++ { 4 | for j:=i+1; j movesMap['L'] { 7 | return movesMap['_'] + movesMap['R'] - movesMap['L'] 8 | } else { 9 | return movesMap['_'] + movesMap['L'] - movesMap['R'] 10 | } 11 | return 0 12 | } 13 | -------------------------------------------------------------------------------- /Golang/Leetcode 2859. Sum of Values at Indices With K Set Bits.go: -------------------------------------------------------------------------------- 1 | func sumIndicesWithKSetBits(nums []int, k int) int { 2 | sum := 0 3 | for i, num := range nums { 4 | if bits.OnesCount(uint(i)) == k { 5 | sum += num 6 | } 7 | } 8 | return sum 9 | } 10 | // func sumIndicesWithKSetBits(nums []int, k int) int { 11 | // l := len(nums) 12 | // sum := 0 13 | // for i:=0; i 0 { 23 | // if num % 2 == 1 { 24 | // count++ 25 | // } 26 | // num /= 2 27 | // } 28 | // return count 29 | // } 30 | -------------------------------------------------------------------------------- /Golang/Leetcode 2864. Maximum Odd Binary Number.go: -------------------------------------------------------------------------------- 1 | func maximumOddBinaryNumber(s string) string { 2 | // countOne := 0 3 | // for _, char := range s { 4 | // if char == '1' { 5 | // countOne++ 6 | // } 7 | // } 8 | // str := "" 9 | // for i:=1; i longDiagonal { 9 | longDiagonal = diagonal 10 | maxArea = len * bre 11 | } else if diagonal == longDiagonal && area > maxArea { 12 | maxArea = area 13 | } 14 | } 15 | return maxArea 16 | } 17 | -------------------------------------------------------------------------------- /Golang/Leetcode 3005. Count Elements With Maximum Frequency.go: -------------------------------------------------------------------------------- 1 | func maxFrequencyElements(nums []int) int { 2 | numsMap := make(map[int]int) 3 | count, max := 0, 0 4 | for _, num := range nums { 5 | numsMap[num]++ 6 | if numsMap[num] > max { 7 | max = numsMap[num] 8 | count = max 9 | } else if numsMap[num] == max { 10 | count += max 11 | } 12 | } 13 | return count 14 | } 15 | -------------------------------------------------------------------------------- /Golang/Leetcode 3099. Harshad Number.go: -------------------------------------------------------------------------------- 1 | func sumOfTheDigitsOfHarshadNumber(x int) int { 2 | digitSum := 0 3 | temp := x 4 | for temp > 0 { 5 | digitSum += temp % 10 6 | temp /= 10 7 | } 8 | if x % digitSum == 0 { 9 | return digitSum 10 | } 11 | return -1 12 | } 13 | -------------------------------------------------------------------------------- /Golang/Leetcode 3115. Maximum Prime Difference.go: -------------------------------------------------------------------------------- 1 | func maximumPrimeDifference(nums []int) int { 2 | left, right := -1, -1 3 | for i := 0; i < len(nums); i++ { 4 | if checkPrime(nums[i]) { 5 | //fmt.Println(nums[i]) 6 | left = i 7 | break 8 | } 9 | } 10 | for i := len(nums)-1; i >= 0; i-- { 11 | if checkPrime(nums[i]) { 12 | //fmt.Println(nums[i]) 13 | right = i 14 | break 15 | } 16 | } 17 | return right - left 18 | } 19 | func checkPrime(num int) bool { 20 | if num == 1 { 21 | return false 22 | }else if num == 2 || num == 3 { 23 | return true 24 | } 25 | for i := 2; i <= int(math.Sqrt(float64(num))); i++ { 26 | if num % i == 0 { 27 | return false 28 | } 29 | } 30 | return true 31 | } 32 | -------------------------------------------------------------------------------- /Golang/Leetcode 326. Power of Three.go: -------------------------------------------------------------------------------- 1 | func isPowerOfThree(n int) bool { 2 | // if n < 1 { 3 | // return false 4 | // } 5 | // for n % 3 == 0 { 6 | // n /= 3 7 | // } 8 | // return n == 1 9 | if n == 1 { 10 | return true 11 | } 12 | if n % 3 != 0 || n <= 0 { 13 | return false 14 | } 15 | return isPowerOfThree(n/3) 16 | } 17 | -------------------------------------------------------------------------------- /Golang/Leetcode 342. Power of Four.go: -------------------------------------------------------------------------------- 1 | func isPowerOfFour(n int) bool { 2 | if n == 1 { 3 | return true 4 | } else if n % 4 != 0 || n == 0{ 5 | return false 6 | } else { 7 | return isPowerOfFour(n/4) 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Golang/Leetcode 349. Intersection of Two Arrays.go: -------------------------------------------------------------------------------- 1 | func intersection(nums1 []int, nums2 []int) []int { 2 | // nums1Map, commonMap := make(map[int]bool, 0), make(map[int]bool, 0) 3 | // for _, num := range nums1 { 4 | // nums1Map[num] = true 5 | // } 6 | // for _, num := range nums2 { 7 | // if nums1Map[num] { 8 | // commonMap[num] = true 9 | // } 10 | // } 11 | // arr := []int 12 | // for key, _ := range commonMap { 13 | // arr = append(arr, key) 14 | // } 15 | // return arr 16 | result := []int{} 17 | nums1Map := make(map[int]bool, 0) 18 | for _, num := range nums1 { 19 | nums1Map[num] = true 20 | } 21 | for _, num := range nums2 { 22 | if nums1Map[num] { 23 | result = append(result, num) 24 | nums1Map[num] = false 25 | } 26 | } 27 | return result 28 | } 29 | -------------------------------------------------------------------------------- /Golang/Leetcode 35 Search Insert Position.go: -------------------------------------------------------------------------------- 1 | func searchInsert(nums []int, target int) int { 2 | left, right := 0, len(nums)-1 3 | mid := (left + right) / 2 4 | for left <= right { 5 | mid = (left + right) / 2 6 | if nums[mid] == target { 7 | return mid 8 | } else if nums[mid] < target { 9 | left = mid + 1 10 | } else if nums[mid] > target { 11 | right = mid - 1 12 | } 13 | } 14 | return left 15 | } 16 | -------------------------------------------------------------------------------- /Golang/Leetcode 350. Intersection of Two Arrays II.go: -------------------------------------------------------------------------------- 1 | func intersect(nums1 []int, nums2 []int) []int { 2 | result := make([]int, 0) 3 | nums1Map := make(map[int]int, 0) 4 | for _, num := range nums1 { 5 | nums1Map[num]++ 6 | } 7 | for _, num := range nums2 { 8 | if nums1Map[num] > 0 { 9 | result = append(result, num) 10 | nums1Map[num]-- 11 | } 12 | } 13 | return result 14 | } 15 | -------------------------------------------------------------------------------- /Golang/Leetcode 367. Valid Perfect Square.go: -------------------------------------------------------------------------------- 1 | func isPerfectSquare(num int) bool { 2 | for i:=1; i<=num; i++ { 3 | if i*i == num { 4 | return true 5 | } else if i*i > num { 6 | return false 7 | } 8 | } 9 | return false 10 | } 11 | -------------------------------------------------------------------------------- /Golang/Leetcode 383. Ransom Note.go: -------------------------------------------------------------------------------- 1 | //array solution (optimised because we know character length is 26 2 | func canConstruct(ransomNote string, magazine string) bool { 3 | ransomArr := make([]int,26) 4 | magazineArr := make([]int,26) 5 | for _, val := range ransomNote { 6 | ransomArr[(int(val - 'a'))]++ 7 | } 8 | for _, val := range magazine { 9 | magazineArr[(int(val - 'a'))]++ 10 | } 11 | fmt.Println(ransomArr) 12 | fmt.Println(magazineArr) 13 | for i, val := range ransomArr { 14 | if val > magazineArr[i] { 15 | return false 16 | } 17 | } 18 | return true 19 | } 20 | 21 | //hashmap solution 22 | func canConstruct(ransomNote string, magazine string) bool { 23 | ransomMap := make(map[rune]int,0) 24 | magazineMap := make(map[rune]int,0) 25 | for _, val := range ransomNote { 26 | ransomMap[val]++ 27 | } 28 | for _, val := range magazine { 29 | magazineMap[val]++ 30 | } 31 | for key, val := range ransomMap { 32 | if magazineMap[key] < val { 33 | return false 34 | } 35 | } 36 | return true 37 | } 38 | -------------------------------------------------------------------------------- /Golang/Leetcode 387. First Unique Character in a String.go: -------------------------------------------------------------------------------- 1 | func firstUniqChar(s string) int { 2 | // charMap := make(map[byte]int, 26) 3 | // for i:=0; i 0; i-- { 8 | if nums[i] != nums[i-1] { 9 | pos++ 10 | } 11 | if pos == 3 { 12 | return nums[i-1] 13 | } 14 | } 15 | return nums[(len(nums)-1)] 16 | } 17 | -------------------------------------------------------------------------------- /Golang/Leetcode 438. Find All Anagrams in a String.go: -------------------------------------------------------------------------------- 1 | func findAnagrams(s string, p string) []int { 2 | l1, l2 := len(s), len(p) 3 | if l1 < l2 { 4 | return []int{} 5 | } 6 | output := []int{} 7 | sArray, pArray := [26]int{}, [26]int{} 8 | for i:=0; i l2 { 4 | return false 5 | } 6 | s1Array, s2Array := [26]int{}, [26]int{} 7 | for i:=0; i len(candyMap) { 7 | return len(candyMap) 8 | } else { 9 | return len(candyType)/2 10 | } 11 | return 1 12 | } 13 | -------------------------------------------------------------------------------- /Golang/Leetcode 58 Length of Last Word.go: -------------------------------------------------------------------------------- 1 | func lengthOfLastWord(s string) int { 2 | s = strings.TrimSpace(s) 3 | result := strings.Split(s," ") 4 | return len(result[len(result)-1]) 5 | } 6 | -------------------------------------------------------------------------------- /Golang/Leetcode 628 Maximum Product of Three Numbers.go: -------------------------------------------------------------------------------- 1 | func maximumProduct(nums []int) int { 2 | sort.Ints(nums) 3 | length := len(nums)-1 4 | return max(nums[length] * nums[length-1] * nums[length-2], nums[0] * nums[1] * nums[length]) 5 | } 6 | -------------------------------------------------------------------------------- /Golang/Leetcode 643. Maximum Average Subarray I.go: -------------------------------------------------------------------------------- 1 | func findMaxAverage(nums []int, k int) float64 { 2 | sum := 0 3 | for i:=0; i high { 10 | high = sum 11 | } 12 | } 13 | return float64(high) / float64(k) 14 | } 15 | -------------------------------------------------------------------------------- /Golang/Leetcode 645 Set Mismatch.go: -------------------------------------------------------------------------------- 1 | func findErrorNums(nums []int) []int { 2 | sum, duplicate := 0, 0 3 | n := len(nums) 4 | numsMap := make(map[int]bool, n) 5 | for _, num := range nums { 6 | if numsMap[num] == true { 7 | duplicate = num 8 | } 9 | sum += num 10 | numsMap[num] = true 11 | } 12 | // sort.Ints(nums) 13 | // for i:=0; i= 0 { 4 | if digits[end] == 9 { 5 | digits[end] = 0 6 | end-- 7 | } else { 8 | digits[end] += 1 9 | break 10 | } 11 | } 12 | if digits[0] == 0 { 13 | digits[0] = 1 14 | digits = append(digits,0) 15 | } 16 | return digits 17 | } 18 | -------------------------------------------------------------------------------- /Golang/Leetcode 7 Reverse Integer.go: -------------------------------------------------------------------------------- 1 | func reverse(x int) int { 2 | reverse := 0 3 | for x != 0 { 4 | reverse = (reverse * 10) + (x % 10) 5 | x = x / 10 6 | if reverse > math.MaxInt32 || reverse < math.MinInt32 { 7 | return 0 8 | } 9 | } 10 | return reverse 11 | } 12 | -------------------------------------------------------------------------------- /Golang/Leetcode 70. Climbing Stairs.go: -------------------------------------------------------------------------------- 1 | func climbStairs(n int) int { 2 | if n == 1 { 3 | return 1 4 | } else if n == 2 { 5 | return 2 6 | } 7 | a, b, fib := 1, 1, 0 8 | for i := 3; i<=n; i++ { 9 | fib = a + b 10 | a = b 11 | b = fib 12 | } 13 | return fib+a 14 | } 15 | -------------------------------------------------------------------------------- /Golang/Leetcode 704 Binary Search.go: -------------------------------------------------------------------------------- 1 | func search(nums []int, target int) int { 2 | left, right := 0, len(nums)-1 3 | mid := left + (right - left) / 2 4 | for left <= right { 5 | mid = (left + right) / 2 6 | if nums[mid] == target { 7 | return mid 8 | } else if nums[mid] < target { 9 | left = mid + 1 10 | } else { 11 | right = mid - 1 12 | } 13 | } 14 | return -1 15 | } 16 | -------------------------------------------------------------------------------- /Golang/Leetcode 709 To Lower Case Inbuilt.go: -------------------------------------------------------------------------------- 1 | //Using inbuilt string methods 2 | func toLowerCase(s string) string { 3 | return strings.ToLower(s) 4 | } 5 | -------------------------------------------------------------------------------- /Golang/Leetcode 709 To Lower Case.go: -------------------------------------------------------------------------------- 1 | func toLowerCase(s string) string { 2 | chars := "" 3 | for i,ch := range s { 4 | if ch >= 65 && ch <= 90 { 5 | chars += string(ch + 32) 6 | } else { 7 | chars += string(s[i]) 8 | } 9 | } 10 | return chars 11 | } 12 | -------------------------------------------------------------------------------- /Golang/Leetcode 744 Find Smallest Letter Greater Than Target.go: -------------------------------------------------------------------------------- 1 | func nextGreatestLetter(letters []byte, target byte) byte { 2 | for _, char := range letters { 3 | if char > target { 4 | return char 5 | } 6 | } 7 | return letters[0] 8 | } 9 | -------------------------------------------------------------------------------- /Golang/Leetcode 771 Jewels and Stones.go: -------------------------------------------------------------------------------- 1 | func numJewelsInStones(jewels string, stones string) int { 2 | jewelMap := make(map[rune]int) 3 | count := 0 4 | for _, ch := range jewels { 5 | jewelMap[ch]++ 6 | } 7 | for _, ch := range stones { 8 | if _, found := jewelMap[ch]; found { 9 | count++ 10 | } 11 | } 12 | return count 13 | } 14 | -------------------------------------------------------------------------------- /Golang/Leetcode 872 Leaf-Similar Trees.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * type TreeNode struct { 4 | * Val int 5 | * Left *TreeNode 6 | * Right *TreeNode 7 | * } 8 | */ 9 | func leafSimilar(root1 *TreeNode, root2 *TreeNode) bool { 10 | tree1 := []int{} 11 | tree2 := []int{} 12 | treeTraversal(root1, &tree1) 13 | treeTraversal(root2, &tree2) 14 | if len(tree1) != len(tree2) { 15 | return false 16 | } 17 | for i:=0; i nums[i+1] { 6 | isIncreasing = false 7 | } else if nums[i] < nums[i+1] { 8 | isDecreasing = false 9 | } 10 | if !isIncreasing && !isDecreasing { 11 | return false 12 | } 13 | } 14 | return isIncreasing || isDecreasing 15 | } 16 | -------------------------------------------------------------------------------- /Golang/Leetcode 9 Palindrome Number.go: -------------------------------------------------------------------------------- 1 | func isPalindrome(x int) bool { 2 | temp := 0 3 | newNum := 0 4 | y := x 5 | for y>0 { 6 | temp = y%10 7 | newNum = newNum*10 + temp 8 | y=y/10 9 | } 10 | if newNum==x{ 11 | return true 12 | }else{ 13 | return false 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Golang/Leetcode 938 Range Sum of BST.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * type TreeNode struct { 4 | * Val int 5 | * Left *TreeNode 6 | * Right *TreeNode 7 | * } 8 | */ 9 | 10 | 11 | func rangeSumBST(root *TreeNode, low int, high int) int { 12 | if root == nil { 13 | return 0 14 | } 15 | if root.Val >= low && root.Val <= high { 16 | return root.Val + rangeSumBST(root.Left,low,high) + rangeSumBST(root.Right,low,high) 17 | } else if root.Val < low { 18 | return rangeSumBST(root.Right,low,high) 19 | } else { 20 | return rangeSumBST(root.Left,low,high) 21 | } 22 | return 0 23 | } 24 | -------------------------------------------------------------------------------- /Golang/Leetcode 94 Binary Tree Inorder Traversal.go: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * type TreeNode struct { 4 | * Val int 5 | * Left *TreeNode 6 | * Right *TreeNode 7 | * } 8 | */ 9 | func inorderTraversal(root *TreeNode) []int { 10 | nums := []int{} 11 | if root == nil { 12 | return nums 13 | } 14 | nums = append(nums, inorderTraversal(root.Left)...) 15 | nums = append(nums, root.Val) 16 | nums = append(nums, inorderTraversal(root.Right)...) 17 | return nums 18 | } 19 | -------------------------------------------------------------------------------- /Golang/Leetcode 961. N-Repeated Element in Size 2N Array.go: -------------------------------------------------------------------------------- 1 | func repeatedNTimes(nums []int) int { 2 | numsMap := make(map[int]bool) 3 | for _, num := range nums { 4 | if numsMap[num] { 5 | return num 6 | } 7 | numsMap[num] = true 8 | } 9 | return 0 10 | } 11 | -------------------------------------------------------------------------------- /Golang/Leetcode 977. Squares of a Sorted Array.go: -------------------------------------------------------------------------------- 1 | // func sortedSquares(nums []int) []int { 2 | // numsSquare := make([]int,len(nums)) 3 | // for i:=0; i rightSqr { 18 | squareArr[i] = leftSqr 19 | left++ 20 | } else { 21 | squareArr[i] = rightSqr 22 | right-- 23 | } 24 | i-- 25 | } 26 | return squareArr 27 | } 28 | -------------------------------------------------------------------------------- /Javascript/test.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /SQL/1068. Product Sales Analysis I.sql: -------------------------------------------------------------------------------- 1 | -- Write your PostgreSQL query statement below 2 | SELECT P.product_name, S.year, S.price 3 | FROM Sales S 4 | INNER JOIN Product P ON S.product_id = P.product_id; 5 | -------------------------------------------------------------------------------- /SQL/1148. Article Views I.sql: -------------------------------------------------------------------------------- 1 | -- Write your PostgreSQL query statement below 2 | SELECT DISTINCT author_id AS id 3 | FROM Views 4 | WHERE author_id = viewer_id 5 | ORDER BY id ASC; 6 | -------------------------------------------------------------------------------- /SQL/1581. Customer Who Visited but Did Not Make Any Transactions.sql: -------------------------------------------------------------------------------- 1 | -- Write your PostgreSQL query statement below 2 | SELECT customer_id, COUNT(*) AS count_no_trans 3 | FROM Visits 4 | WHERE visit_id NOT IN (SELECT visit_id FROM Transactions) 5 | GROUP BY customer_id; 6 | --SELECT V.customer_id, COUNT(*) AS count_no_trans 7 | --FROM Visits AS V 8 | --LEFT JOIN Transactions AS T ON V.visit_id = T.visit_id 9 | --WHERE T.transaction_id IS NULL 10 | --GROUP BY V.customer_id; 11 | -------------------------------------------------------------------------------- /SQL/1683. Invalid Tweets.sql: -------------------------------------------------------------------------------- 1 | -- Write your PostgreSQL query statement below 2 | SELECT tweet_id 3 | FROM Tweets 4 | WHERE LENGTH(content) > 15; 5 | -------------------------------------------------------------------------------- /SQL/1757. Recyclable and Low Fat Products.sql: -------------------------------------------------------------------------------- 1 | -- Write your PostgreSQL query statement below 2 | SELECT product_id 3 | FROM Products 4 | WHERE low_fats = 'Y' AND recyclable = 'Y'; 5 | -------------------------------------------------------------------------------- /SQL/2356. Number of Unique Subjects Taught by Each Teacher.sql: -------------------------------------------------------------------------------- 1 | # Write your MySQL query statement below 2 | SELECT teacher_id, COUNT(DISTINCT(subject_id)) AS cnt 3 | FROM Teacher 4 | GROUP BY teacher_id; 5 | -------------------------------------------------------------------------------- /SQL/584. Find Customer Referee.go: -------------------------------------------------------------------------------- 1 | -- Write your PostgreSQL query statement below 2 | SELECT name 3 | FROM Customer 4 | WHERE referee_id <> 2 OR referee_id IS NULL; 5 | -------------------------------------------------------------------------------- /SQL/595. Big Countries.sql: -------------------------------------------------------------------------------- 1 | -- Write your PostgreSQL query statement below 2 | SELECT name,population,area 3 | FROM World 4 | WHERE area >= 3000000 OR population >= 25000000; 5 | -------------------------------------------------------------------------------- /SQL/Leetcode 1378. Replace Employee ID With The Unique Identifier.sql: -------------------------------------------------------------------------------- 1 | -- Write your PostgreSQL query statement below 2 | SELECT EmployeeUNI.unique_id, Employees.name 3 | FROM Employees 4 | LEFT JOIN EmployeeUNI ON Employees.id = EmployeeUNI.id; 5 | -------------------------------------------------------------------------------- /School/Sum of Series/sum-of-series.py: -------------------------------------------------------------------------------- 1 | 2 | class Solution: 3 | def seriesSum(self, n : int) -> int: 4 | # code here 5 | return n * (n+1) // 2 6 | 7 | 8 | 9 | #{ 10 | # Driver Code Starts 11 | if __name__ == '__main__': 12 | t = int(input()) 13 | for _ in range(t): 14 | 15 | n = int(input()) 16 | 17 | obj = Solution() 18 | res = obj.seriesSum(n) 19 | 20 | print(res) 21 | 22 | # } Driver Code Ends --------------------------------------------------------------------------------