Skip to content

Files

405 lines (398 loc) · 101 KB

README.md

File metadata and controls

405 lines (398 loc) · 101 KB

leetcode-ruby

About

Some solved problems from LeetCode on Ruby.

Links

Profile on LeetCode: fartem.

Solutions

Easy

Name Link to LeetCode Link to solution
1. Two Sum Link Link
9. Palindrome Number Link Link
13. Roman to Integer Link Link
14. Longest Common Prefix Link Link
20. Valid Parentheses Link Link
21. Merge Two Sorted Lists Link Link
26. Remove Duplicates from Sorted Array Link Link
27. Remove Element Link Link
28. Find the Index of the First Occurrence in a String Link Link
35. Search Insert Position Link Link
58. Length of Last Word Link Link
66. Plus One Link Link
67. Add Binary Link Link
69. Sqrt(x) Link Link
70. Climbing Stairs Link Link
83. Remove Duplicates from Sorted List Link Link
88. Merge Sorted Array Link Link
94. Binary Tree Inorder Traversal Link Link
100. Same Tree Link Link
101. Symmetric Tree Link Link
104. Maximum Depth of Binary Tree Link Link
108. Convert Sorted Array to Binary Search Tree Link Link
110. Balanced Binary Tree Link Link
111. Minimum Depth of Binary Tree Link Link
112. Path Sum Link Link
118. Pascal's Triangle Link Link
119. Pascal's Triangle II Link Link
121. Best Time to Buy and Sell Stock Link Link
125. Valid Palindrome Link Link
136. Single Number Link Link
141. Linked List Cycle Link Link
144. Binary Tree Preorder Traversal Link Link
145. Binary Tree Postorder Traversal Link Link
160. Intersection of Two Linked Lists Link Link
168. Excel Sheet Column Title Link Link
169. Majority Element Link Link
171. Excel Sheet Column Number Link Link
190. Reverse Bits Link Link
191. Number of 1 Bits Link Link
202. Happy Number Link Link
203. Remove Linked List Elements Link Link
205. Isomorphic Strings Link Link
206. Reverse Linked List Link Link
217. Contains Duplicate Link Link
219. Contains Duplicate II Link Link
225. Implement Stack using Queues Link Link
226. Invert Binary Tree Link Link
228. Summary Ranges Link Link
231. Power of Two Link Link
232. Implement Queue using Stacks Link Link
234. Palindrome Linked List Link Link
242. Valid Anagram Link Link
257. Binary Tree Paths Link Link
258. Add Digits Link Link
263. Ugly Number Link Link
268. Missing Number Link Link
278. First Bad Version Link Link
283. Move Zeroes Link Link
290. Word Pattern Link Link
292. Nim Game Link Link
303. Range Sum Query - Immutable Link Link
326. Power of Three Link Link
338. Counting Bits Link Link
342. Power of Four Link Link
344. Reverse String Link Link
345. Reverse Vowels of a String Link Link
349. Intersection of Two Arrays Link Link
350. Intersection of Two Arrays II Link Link
367. Valid Perfect Square Link Link
374. Guess Number Higher or Lower Link Link
383. Ransom Note Link Link
387. First Unique Character in a String Link Link
389. Find the Difference Link Link
392. Is Subsequence Link Link
404. Sum of Left Leaves Link Link
405. Convert a Number to Hexadecimal Link Link
409. Longest Palindrome Link Link
412. Fizz Buzz Link Link
414. Third Maximum Number Link Link
415. Add Strings Link Link
434. Number of Segments in a String Link Link
441. Arranging Coins Link Link
448. Find All Numbers Disappeared in an Array Link Link
455. Assign Cookies Link Link
459. Repeated Substring Pattern Link Link
461. Hamming Distance Link Link
463. Island Perimeter Link Link
476. Number Complement Link Link
482. License Key Formatting Link Link
485. Max Consecutive Ones Link Link
492. Construct the Rectangle Link Link
496. Next Greater Element I Link Link
500. Keyboard Row Link Link
501. Find Mode in Binary Search Tree Link Link
504. Base 7 Link Link
506. Relative Ranks Link Link
507. Perfect Number Link Link
509. Fibonacci Number Link Link
520. Detect Capital Link Link
521. Longest Uncommon Subsequence I Link Link
530. Minimum Absolute Difference in BST Link Link
543. Diameter of Binary Tree Link Link
551. Student Attendance Record I Link Link
557. Reverse Words in a String III Link Link
559. Maximum Depth of N-ary Tree Link Link
561. Array Partition Link Link
563. Binary Tree Tilt Link Link
566. Reshape the Matrix Link Link
572. Subtree of Another Tree Link Link
589. N-ary Tree Preorder Traversal Link Link
590. N-ary Tree Postorder Traversal Link Link
594. Longest Harmonious Subsequence Link Link
599. Minimum Index Sum of Two Lists Link Link
606. Construct String from Binary Tree Link Link
617. Merge Two Binary Trees Link Link
628. Maximum Product of Three Numbers Link Link
637. Average of Levels in Binary Tree Link Link
643. Maximum Average Subarray I Link Link
645. Set Mismatch Link Link
653. Two Sum IV - Input is a BST Link Link
657. Robot Return to Origin Link Link
671. Second Minimum Node In a Binary Tree Link Link
674. Longest Continuous Increasing Subsequence Link Link
680. Valid Palindrome II Link Link
682. Baseball Game Link Link
693. Binary Number with Alternating Bits Link Link
700. Search in a Binary Search Tree Link Link
703. Kth Largest Element in a Stream Link Link
704. Binary Search Link Link
705. Design HashSet Link Link
706. Design HashMap Link Link
709. To Lower Case Link Link
717. 1-bit and 2-bit Characters Link Link
724. Find Pivot Index Link Link
728. Self Dividing Numbers Link Link
733. Flood Fill Link Link
744. Find Smallest Letter Greater Than Target Link Link
746. Min Cost Climbing Stairs Link Link
747. Largest Number At Least Twice of Others Link Link
762. Prime Number of Set Bits in Binary Representation Link Link
766. Toeplitz Matrix Link Link
771. Jewels and Stones Link Link
783. Minimum Distance Between BST Nodes Link Link
796. Rotate String Link Link
804. Unique Morse Code Words Link Link
806. Number of Lines To Write String Link Link
812. Largest Triangle Area Link Link
819. Most Common Word Link Link
821. Shortest Distance to a Character Link Link
830. Positions of Large Groups Link Link
832. Flipping an Image Link Link
844. Backspace String Compare Link Link
859. Buddy Strings Link Link
860. Lemonade Change Link Link
867. Transpose Matrix Link Link
868. Binary Gap Link Link
872. Leaf-Similar Trees Link Link
876. Middle of the Linked List Link Link
884. Uncommon Words from Two Sentences Link Link
896. Monotonic Array Link Link
897. Increasing Order Search Tree Link Link
905. Sort Array By Parity Link Link
908. Smallest Range I Link Link
917. Reverse Only Letters Link Link
922. Sort Array By Parity II Link Link
925. Long Pressed Name Link Link
929. Unique Email Addresses Link Link
933. Number of Recent Calls Link Link
938. Range Sum of BST Link Link
941. Valid Mountain Array Link Link
942. DI String Match Link Link
944. Delete Columns to Make Sorted Link Link
953. Verifying an Alien Dictionary Link Link
961. N-Repeated Element in Size 2N Array Link Link
965. Univalued Binary Tree Link Link
976. Largest Perimeter Triangle Link Link
977. Squares of a Sorted Array Link Link
989. Add to Array-Form of Integer Link Link
993. Cousins in Binary Tree Link Link
997. Find the Town Judge Link Link
1002. Find Common Characters Link Link
1005. Maximize Sum Of Array After K Negations Link Link
1009. Complement of Base 10 Integer Link Link
1018. Binary Prefix Divisible By 5 Link Link
1021. Remove Outermost Parentheses Link Link
1022. Sum of Root To Leaf Binary Numbers Link Link
1025. Divisor Game Link Link
1046. Last Stone Weight Link Link
1047. Remove All Adjacent Duplicates In String Link Link
1051. Height Checker Link Link
1071. Greatest Common Divisor of Strings Link Link
1078. Occurrences After Bigram Link Link
1089. Duplicate Zeros Link Link
1103. Distribute Candies to People Link Link
1108. Defanging an IP Address Link Link
1137. N-th Tribonacci Number Link Link
1154. Day of the Year Link Link
1160. Find Words That Can Be Formed by Characters Link Link
1184. Distance Between Bus Stops Link Link
1185. Day of the Week Link Link
1189. Maximum Number of Balloons Link Link
1200. Minimum Absolute Difference Link Link
1207. Unique Number of Occurrences Link Link
1217. Minimum Cost to Move Chips to The Same Position Link Link
1221. Split a String in Balanced Strings Link Link
1232. Check If It Is a Straight Line Link Link
1252. Cells with Odd Values in a Matrix Link Link
1266. Minimum Time Visiting All Points Link Link
1275. Find Winner on a Tic Tac Toe Game Link Link
1281. Subtract the Product and Sum of Digits of an Integer Link Link
1287. Element Appearing More Than 25% In Sorted Array Link Link
1290. Convert Binary Number in a Linked List to Integer Link Link
1295. Find Numbers with Even Number of Digits Link Link
1299. Replace Elements with Greatest Element on Right Side Link Link
1304. Find N Unique Integers Sum up to Zero Link Link
1309. Decrypt String from Alphabet to Integer Mapping Link Link
1313. Decompress Run-Length Encoded List Link Link
1317. Convert Integer to the Sum of Two No-Zero Integers Link Link
1323. Maximum 69 Number Link Link
1332. Remove Palindromic Subsequences Link Link
1337. The K Weakest Rows in a Matrix Link Link
1342. Number of Steps to Reduce a Number to Zero Link Link
1346. Check If N and Its Double Exist Link Link
1351. Count Negative Numbers in a Sorted Matrix Link Link
1356. Sort Integers by The Number of 1 Bits Link Link
1360. Number of Days Between Two Dates Link Link
1365. How Many Numbers Are Smaller Than the Current Number Link Link
1370. Increasing Decreasing String Link Link
1374. Generate a String With Characters That Have Odd Counts Link Link
1385. Find the Distance Value Between Two Arrays Link Link
1389. Create Target Array in the Given Order Link Link
1399. Count Largest Group Link Link
1403. Minimum Subsequence in Non-Increasing Order Link Link
1408. String Matching in an Array Link Link
1413. Minimum Value to Get Positive Step by Step Sum Link Link
1417. Reformat The String Link Link
1422. Maximum Score After Splitting a String Link Link
1431. Kids With the Greatest Number of Candies Link Link
1436. Destination City Link Link
1437. Check If All 1's Are at Least Length K Places Away Link Link
1446. Consecutive Characters Link Link
1450. Number of Students Doing Homework at a Given Time Link Link
1455. Check If a Word Occurs As a Prefix of Any Word in a Sentence Link Link
1460. Make Two Arrays Equal by Reversing Subarrays Link Link
1464. Maximum Product of Two Elements in an Array Link Link
1470. Shuffle the Array Link Link
1475. Final Prices With a Special Discount in a Shop Link Link
1480. Running Sum of 1d Array Link Link
1486. XOR Operation in an Array Link Link
1491. Average Salary Excluding the Minimum and Maximum Salary Link Link
1496. Path Crossing Link Link
1502. Can Make Arithmetic Progression From Sequence Link Link
1507. Reformat Date Link Link
1512. Number of Good Pairs Link Link
1518. Water Bottle Link Link
1523. Count Odd Numbers in an Interval Range Link Link
1528. Shuffle String Link Link
1534. Count Good Triplets Link Link
1539. Kth Missing Positive Number Link Link
1544. Make The String Great Link Link
1550. Three Consecutive Odds Link Link
1556. Thousand Separator Link Link
1566. Detect Pattern of Length M Repeated K or More Times Link Link
1572. Matrix Diagonal Sum Link Link
1576. Replace All ?'s to Avoid Consecutive Repeating Characters Link Link
1582. Special Positions in a Binary Matrix Link Link
1588. Sum of All Odd Length Subarrays Link Link
1592. Rearrange Spaces Between Words Link Link
1598. Crawler Log Folder Link Link
1603. Design Parking System Link Link
1608. Special Array With X Elements Greater Than or Equal X Link Link
1614. Maximum Nesting Depth of the Parentheses Link Link
1619. Mean of Array After Removing Some Elements Link Link
1624. Largest Substring Between Two Equal Characters Link Link
1629. Slowest Key Link Link
1636. Sort Array by Increasing Frequency Link Link
1646. Get Maximum in Generated Array Link Link
1652. Defuse the Bomb Link Link
1662. Check If Two String Arrays are Equivalent Link Link
1668. Maximum Repeating Substring Link Link
1672. Richest Customer Wealth Link Link
1678. Goal Parser Interpretation Link Link
1684. Count the Number of Consistent Strings Link Link
1688. Count of Matches in Tournament Link Link
1694. Reformat Phone Number Link Link
1700. Number of Students Unable to Eat Lunch Link Link
1704. Determine if String Halves Are Alike Link Link
1710. Maximum Units on a Truck Link Link
1716. Calculate Money in Leetcode Bank Link Link
1720. Decode XORed Array Link Link
1725. Number Of Rectangles That Can Form The Largest Square Link Link
1732. Find the Highest Altitude Link Link
1736. Latest Time by Replacing Hidden Digits Link Link
1748. Sum of Unique Elements Link Link
1752. Check if Array Is Sorted and Rotated Link Link
1768. Merge Strings Alternately Link Link
1773. Count Items Matching a Rule Link Link
1779. Find Nearest Point That Has the Same X or Y Coordinate Link Link
1784. Check if Binary String Has at Most One Segment of Ones Link Link
1790. Check if One String Swap Can Make Strings Equal Link Link
1791. Find Center of Star Graph Link Link
1796. Second Largest Digit in a String Link Link
1800. Maximum Ascending Subarray Sum Link Link
1805. Number of Different Integers in a String Link Link
1812. Determine Color of a Chessboard Square Link Link
1816. Truncate Sentence Link Link
1822. Sign of the Product of an Array Link Link
1827. Minimum Operations to Make the Array Increasing Link Link
1832. Check if the Sentence Is Pangram Link Link
1837. Sum of Digits in Base K Link Link
1844. Replace All Digits with Characters Link Link
1848. Minimum Distance to the Target Element Link Link
1859. Sorting the Sentence Link Link
1863. Sum of All Subset XOR Totals Link Link
1869. Longer Contiguous Segments of Ones than Zeros Link Link
1876. Substrings of Size Three with Distinct Characters Link Link
1880. Check if Word Equals Summation of Two Words Link Link
1886. Determine Whether Matrix Can Be Obtained By Rotation Link Link
1893. Check if All the Integers in a Range Are Covered Link Link
1897. Redistribute Characters to Make All Strings Equal Link Link
1903. Largest Odd Number in String Link Link
1909. Remove One Element to Make the Array Strictly Increasing Link Link
1913. Maximum Product Difference Between Two Pairs Link Link
1920. Build Array from Permutation Link Link
1925. Count Square Sum Triples Link Link
1929. Concatenation of Array Link Link
1935. Maximum Number of Words You Can Type Link Link
1941. Check if All Characters Have Equal Number of Occurrences Link Link
1952. Three Divisors Link Link
1957. Delete Characters to Make Fancy String Link Link
1961. Check If String Is a Prefix of Array Link Link
1967. Number of Strings That Appear as Substrings in Word Link Link
1971. Find if Path Exists in Graph Link Link
1974. Minimum Time to Type Word Using Special Typewriter Link Link
1979. Find Greatest Common Divisor of Array Link Link
1984. Minimum Difference Between Highest and Lowest of K Scores Link Link
1991. Find the Middle Index in Array Link Link
1995. Count Special Quadruplets Link Link
2000. Reverse Prefix of Word Link Link
2006. Count Number of Pairs With Absolute Difference K Link Link
2011. Final Value of Variable After Performing Operations Link Link
2016. Maximum Difference Between Increasing Elements Link Link
2022. Convert 1D Array Into 2D Array Link Link
2027. Minimum Moves to Convert String Link Link
2032. Two Out of Three Link Link
2037. Minimum Number of Moves to Seat Everyone Link Link
2042. Check if Numbers Are Ascending in a Sentence Link Link
2047. Number of Valid Words in a Sentence Link Link
2053. Kth Distinct String in an Array Link Link
2057. Smallest Index With Equal Value Link Link
2062. Count Vowel Substrings of a String Link Link
2068. Check Whether Two Strings are Almost Equivalent Link Link
2073. Time Needed to Buy Tickets Link Link
2078. Two Furthest Houses With Different Colors Link Link
2085. Count Common Words With One Occurrence Link Link
2089. Find Target Indices After Sorting Array Link Link
2094. Finding 3-Digit Even Numbers Link Link
2099. Find Subsequence of Length K With the Largest Sum Link Link
2103. Rings and Rods Link Link
2108. Find First Palindromic String in the Array Link Link
2114. Maximum Number of Words Found in Sentences Link Link
2119. A Number After a Double Reversal Link Link
2124. Check if All A's Appears Before All B's Link Link
2129. Capitalize the Title Link Link
2133. Check if Every Row and Column Contains All Numbers Link Link
2138. Divide a String Into Groups of Size k Link Link
2148. Count Elements With Strictly Smaller and Greater Elements Link Link
2154. Keep Multiplying Found Values by Two Link Link
2160. Minimum Sum of Four Digit Number After Splitting Digits Link Link
2164. Sort Even and Odd Indices Independently Link Link
2169. Count Operations to Obtain Zero Link Link
2176. Count Equal and Divisible Pairs in an Array Link Link
2180. Count Integers With Even Digit Sum Link Link
2185. Counting Words With a Given Prefix Link Link
2190. Most Frequent Number Following Key In an Array Link Link
2194. Cells in a Range on an Excel Sheet Link Link
2206. Divide Array Into Equal Pairs Link Link
2210. Count Hills and Valleys in an Array Link Link
2215. Find the Difference of Two Arrays Link Link
2220. Minimum Bit Flips to Convert Number Link Link
2231. Largest Number After Digit Swaps by Parity Link Link
2235. Add Two Integers Link Link
2236. Root Equals Sum of Children Link Link
2239. Find Closest Number to Zero Link Link
2243. Calculate Digit Sum of a String Link Link
2248. Intersection of Multiple Arrays Link Link
2255. Count Prefixes of a Given String Link Link
2259. Remove Digit From Number to Maximize Result Link Link
2264. Largest 3-Same-Digit Number in String Link Link