├── solutions ├── 2917. Find the K-or of an Array │ ├── 2917.cpp │ └── 2917.py ├── 195. Tenth Line │ └── 195.sh ├── 2446. Determine if Two Events Have Conflict │ ├── 2446.py │ ├── 2446.cpp │ └── 2446.java ├── 2259. Remove Digit From Number to Maximize Result │ └── 2259.py ├── 2235. Add Two Integers │ ├── 2235.py │ ├── 2235.java │ └── 2235.cpp ├── .DS_Store ├── 627. Swap Salary │ └── 627.sql ├── 1683. Invalid Tweets │ └── 1683.sql ├── 182. Duplicate Emails │ └── 182.sql ├── 1853. Convert Date Format │ └── 1853.sql ├── 192. Word Frequency │ └── 192.sh ├── 292. Nim Game │ ├── 292.py │ ├── 292.cpp │ └── 292.java ├── 1025. Divisor Game │ ├── 1025.py │ ├── 1025.java │ └── 1025.cpp ├── 584. Find Customer Referee │ └── 584.sql ├── 596. Classes More Than 5 Students │ └── 596.sql ├── 1256. Encode Number │ ├── 1256.py │ ├── 1256.java │ └── 1256.cpp ├── 178. Rank Scores │ └── 178.sql ├── 511. Game Play Analysis I │ └── 511.sql ├── 1069. Product Sales Analysis II │ └── 1069.sql ├── 191. Number of 1 Bits │ ├── 191-2.py │ ├── 191-2.cpp │ ├── 191-2.java │ ├── 191.py │ └── 191.cpp ├── 595. Big Countries │ └── 595.sql ├── 1148. Article Views I │ └── 1148.sql ├── 1688. Count of Matches in Tournament │ ├── 1688.py │ ├── 1688.java │ └── 1688.cpp ├── 1757. Recyclable and Low Fat Products │ └── 1757.sql ├── 258. Add Digits │ ├── 258.java │ ├── 258.cpp │ └── 258.py ├── 1303. Find the Team Size │ └── 1303.sql ├── 193. Valid Phone Numbers │ └── 193.sh ├── 2026. Low-Quality Problems │ └── 2026.sql ├── 2082. The Number of Rich Customers │ └── 2082.sql ├── 2109. Adding Spaces to a String │ └── 2109.cpp ├── 231. Power of Two │ ├── 231.py │ ├── 231.java │ └── 231.cpp ├── 2396. Strictly Palindromic Number │ ├── 2396.py │ ├── 2396.java │ └── 2396.cpp ├── 2620. Counter │ └── 2620.ts ├── 2687. Bikes Last Time Used │ └── 2687.sql ├── 2716. Minimize String Length │ ├── 2716.py │ ├── 2716.cpp │ └── 2716.java ├── 326. Power of Three │ ├── 326.py │ ├── 326.java │ └── 326.cpp ├── 434. Number of Segments in a String │ └── 434.py ├── 613. Shortest Distance in a Line │ └── 613.sql ├── 2413. Smallest Even Multiple │ ├── 2413.py │ ├── 2413.java │ └── 2413.cpp ├── 2549. Count Distinct Numbers on Board │ ├── 2549.py │ ├── 2549.cpp │ └── 2549.java ├── 561. Array Partition I │ └── 561.py ├── 610. Triangle Judgement │ └── 610.sql ├── 626. Exchange Seats │ └── 626.sql ├── 1119. Remove Vowels from a String │ ├── 1119.py │ └── 1119.java ├── 151. Reverse Words in a String │ └── 151.py ├── 1556. Thousand Separator │ └── 1556.py ├── 1816. Truncate Sentence │ ├── 1816.py │ └── 1816.cpp ├── 1929. Concatenation of Array │ └── 1929.py ├── 2005. Subtree Removal Game with Fibonacci Tree │ ├── 2005.py │ ├── 2005.java │ └── 2005.cpp ├── 2124. Check if All A's Appears Before All B's │ ├── 2124.py │ ├── 2124.java │ └── 2124.cpp ├── 2579. Count Total Number of Colored Cells │ ├── 2579.py │ ├── 2579.java │ └── 2579.cpp ├── 3358. Books with NULL Ratings │ └── 3358.sql ├── 3436. Find Valid Emails │ └── 3436.sql ├── 441. Arranging Coins │ ├── 441.py │ ├── 441.cpp │ └── 441.java ├── 1108. Defanging an IP Address │ ├── 1108.py │ ├── 1108.java │ └── 1108.cpp ├── 1323. Maximum 69 Number │ └── 1323.py ├── 1445. Apples & Oranges │ └── 1445.sql ├── 1517. Find Users With Valid E-Mails │ └── 1517.sql ├── 1527. Patients With a Condition │ └── 1527.sql ├── 1821. Find Customers With Positive Revenue this Year │ └── 1821.sql ├── 1908. Game of Nim │ ├── 1908.py │ ├── 1908.java │ └── 1908.cpp ├── 217. Contains Duplicate │ └── 217.py ├── 459. Repeated Substring Pattern │ ├── 459.py │ ├── 459.java │ └── 459.cpp ├── 507. Perfect Number │ └── 507.py ├── 620. Not Boring Movies │ └── 620.sql ├── 660. Remove 9 │ ├── 660.java │ ├── 660.py │ └── 660.cpp ├── 1304. Find N Unique Integers Sum up to Zero │ ├── 1304.py │ ├── 1304.java │ └── 1304.cpp ├── 1332. Remove Palindromic Subsequences │ ├── 1332.py │ ├── 1332.cpp │ └── 1332.java ├── 136. Single Number │ ├── 136.py │ ├── 136.java │ └── 136.cpp ├── 1480. Running Sum of 1d Array │ └── 1480.py ├── 1729. Find Followers Count │ └── 1729.sql ├── 196. Delete Duplicate Emails │ └── 196.sql ├── 2710. Remove Trailing Zeros From a String │ ├── 2710.py │ ├── 2710.java │ └── 2710.cpp ├── 3370. Smallest Number With All Set Bits │ └── 3370.py ├── 551. Student Attendance Record I │ ├── 551.py │ └── 551.java ├── 586. Customer Placing the Largest Number of Orders │ └── 586.sql ├── 796. Rotate String │ ├── 796.py │ ├── 796.java │ └── 796.cpp ├── 1227. Airplane Seat Assignment Probability │ ├── 1227.py │ ├── 1227.java │ └── 1227.cpp ├── 1393. Capital Gain/Loss │ └── 1393.sql ├── 1672. Richest Customer Wealth │ ├── 1672.py │ └── 1672.java ├── 1689. Partitioning Into Minimum Number Of Deci-Binary Numbers │ ├── 1689.py │ ├── 1689.cpp │ └── 1689.java ├── 1832. Check if the Sentence Is Pangram │ ├── 1832.py │ ├── 1832.cpp │ └── 1832-2.py ├── 205. Isomorphic Strings │ └── 205.py ├── 2119. A Number After a Double Reversal │ ├── 2119-2.py │ ├── 2119-2.cpp │ └── 2119-2.java ├── 237. Delete Node in a Linked List │ ├── 237.py │ ├── 237.java │ └── 237.cpp ├── 2527. Find Xor-Beauty of Array │ ├── 2527.py │ ├── 2527.java │ └── 2527.cpp ├── 2667. Create Hello World Function │ └── 2667.ts ├── 2769. Find the Maximum Achievable Number │ ├── 2769.py │ ├── 2769.java │ └── 2769.cpp ├── 2987. Find Expensive Cities │ └── 2987.sql ├── 1421. NPV Queries │ └── 1421.sql ├── 1784. Check if Binary String Has at Most One Segment of Ones │ ├── 1784.py │ ├── 1784.java │ └── 1784.cpp ├── 1890. The Latest Login in 2020 │ └── 1890.sql ├── 1979. Find Greatest Common Divisor of Array │ ├── 1979.py │ └── 1979.cpp ├── 2356. Number of Unique Subjects Taught by Each Teacher │ └── 2356.sql ├── 2878. Get the Size of a DataFrame │ └── 2878.py ├── 3210. Find the Encrypted String │ ├── 3210.py │ ├── 3210.cpp │ └── 3210.java ├── 520. Detect Capital │ ├── 520.py │ └── 520.java ├── 577. Employee Bonus │ └── 577.sql ├── 908. Smallest Range I │ ├── 908.py │ └── 908.cpp ├── 1050. Actors and Directors Who Cooperated At Least Three Times │ └── 1050.sql ├── 1678. Goal Parser Interpretation │ └── 1678.py ├── 172. Factorial Trailing Zeroes │ ├── 172.py │ ├── 172.java │ └── 172.cpp ├── 2220. Minimum Bit Flips to Convert Number │ ├── 2220.py │ ├── 2220.java │ └── 2220.cpp ├── 2278. Percentage of Letter in String │ ├── 2278.py │ ├── 2278.cpp │ └── 2278.java ├── 2298. Tasks Count in the Weekend │ └── 2298.sql ├── 2357. Make Array Zero by Subtracting Equal Amounts │ ├── 2357.py │ └── 2357.cpp ├── 2520. Count the Digits That Divide a Number │ └── 2520.py ├── 2621. Sleep │ └── 2621.ts ├── 2802. Find The K-th Lucky Number │ └── 2802.py ├── 2879. Display the First Three Rows │ └── 2879.py ├── 2886. Change Data Type │ └── 2886.py ├── 3204. Bitwise User Permissions Analysis │ └── 3204.sql ├── 3536. Maximum Product of Two Digits │ └── 3536.py ├── 390. Elimination Game │ ├── 390.java │ ├── 390.py │ └── 390.cpp ├── 521. Longest Uncommon Subsequence I │ ├── 521.py │ ├── 521.cpp │ └── 521.java ├── 575. Distribute Candies │ └── 575.py ├── 709. To Lower Case │ └── 709.py ├── 1068. Product Sales Analysis I │ └── 1068.sql ├── 1149. Article Views II │ └── 1149.sql ├── 1561. Maximum Number of Coins You Can Get │ └── 1561.py ├── 1873. Calculate Special Bonus │ └── 1873.sql ├── 2236. Root Equals Sum of Children │ ├── 2236.py │ ├── 2236.java │ └── 2236.cpp ├── 2255. Count Prefixes of a Given String │ ├── 2255.py │ ├── 2255.java │ └── 2255.cpp ├── 2335. Minimum Amount of Time to Fill Cups │ └── 2335.py ├── 2469. Convert the Temperature │ ├── 2469.py │ ├── 2469.cpp │ └── 2469.java ├── 2504. Concatenate the Name and the Profession │ └── 2504.sql ├── 2656. Maximum Sum With Exactly K Elements │ └── 2656.py ├── 2669. Count Artist Occurrences On Spotify Ranking List │ └── 2669.sql ├── 2733. Neither Minimum nor Maximum │ ├── 2733.py │ ├── 2733.java │ └── 2733.cpp ├── 2923. Find Champion I │ ├── 2923-2.py │ └── 2923-2.java ├── 3151. Special Array I │ ├── 3151.py │ ├── 3151.java │ └── 3151.cpp ├── 3198. Find Cities in Each State │ └── 3198.sql ├── 3304. Find the K-th Character in String Game I │ ├── 3304.py │ ├── 3304.cpp │ └── 3304.java ├── 3353. Minimum Total Operations │ └── 3353.py ├── 3492. Maximum Containers on a Ship │ ├── 3492.py │ ├── 3492.java │ └── 3492.cpp ├── 3512. Minimum Operations to Make Array Sum Divisible by K │ ├── 3512.py │ ├── 3512.java │ └── 3512.cpp ├── 3560. Find Minimum Log Transportation Cost │ ├── 3560.py │ ├── 3560.java │ └── 3560.cpp ├── 1085. Sum of Digits in the Minimum Number │ └── 1085.py ├── 1641. Count Sorted Vowel Strings │ ├── 1641-2.java │ └── 1641-2.cpp ├── 2678. Number of Senior Citizens │ ├── 2678.py │ ├── 2678.cpp │ └── 2678.java ├── 2683. Neighboring Bitwise XOR │ └── 2683.py ├── 2864. Maximum Odd Binary Number │ └── 2864.py ├── 2990. Loan Types │ └── 2990.sql ├── 3131. Find the Integer Added to Array I │ ├── 3131.py │ ├── 3131.cpp │ └── 3131.java ├── 3173. Bitwise OR of Adjacent Elements │ └── 3173.py ├── 3502. Minimum Cost to Reach Every Position │ └── 3502.py ├── 810. Chalkboard XOR Game │ ├── 810.py │ ├── 810.java │ └── 810.cpp ├── 1134. Armstrong Number │ └── 1134.py ├── 1173. Immediate Food Delivery I │ └── 1173.sql ├── 1378. Replace Employee ID With The Unique Identifier │ └── 1378.sql ├── 1523. Count Odd Numbers in an Interval Range │ └── 1523.cpp ├── 1741. Find Total Time Spent by Each Employee │ └── 1741.sql ├── 1863. Sum of All Subset XOR Totals │ ├── 1863-2.py │ ├── 1863-2.java │ └── 1863-2.cpp ├── 2000. Reverse Prefix of Word │ ├── 2000.py │ └── 2000.cpp ├── 2144. Minimum Cost of Buying Candies With Discount │ └── 2144.py ├── 2214. Minimum Health to Beat Game │ └── 2214.py ├── 2543. Check if Point Is Reachable │ ├── 2543.py │ └── 2543.cpp ├── 2546. Apply Bitwise Operations to Make Strings Equal │ ├── 2546.py │ ├── 2546.java │ └── 2546.cpp ├── 2553. Separate the Digits in an Array │ └── 2553.py ├── 2578. Split With Minimum Sum │ └── 2578.py ├── 2893. Calculate Orders Within Each Interval │ └── 2893.sql ├── 2980. Check if Bitwise OR Has Trailing Zeros │ └── 2980.py ├── 3046. Split the Array │ └── 3046.py ├── 3065. Minimum Operations to Exceed Threshold Value I │ ├── 3065.py │ ├── 3065.java │ └── 3065.cpp ├── 3179. Find the N-th Value After K Seconds │ └── 3179.py ├── 3222. Find the Winning Player in Coin Game │ ├── 3222.py │ ├── 3222.java │ └── 3222.cpp ├── 3232. Find if Digit Game Can Be Won │ ├── 3232.py │ └── 3232.java ├── 3340. Check Balanced String │ └── 3340.py ├── 453. Minimum Moves to Equal Array Elements │ └── 453.py ├── 541. Reverse String II │ └── 541.py ├── 69. Sqrt(x) │ └── 69.py ├── 1045. Customers Who Bought All Products │ └── 1045.sql ├── 1356. Sort Integers by The Number of 1 Bits │ └── 1356.py ├── 175. Combine Two Tables │ └── 175.sql ├── 1805. Number of Different Integers in a String │ └── 1805-2.py ├── 183. Customers Who Never Order │ └── 183.sql ├── 201. Bitwise AND of Numbers Range │ └── 201.py ├── 2114. Maximum Number of Words Found in Sentences │ └── 2114.py ├── 2185. Counting Words With a Given Prefix │ ├── 2185.py │ ├── 2185.java │ └── 2185.cpp ├── 2239. Find Closest Number to Zero │ └── 2239.py ├── 2481. Minimum Cuts to Divide a Circle │ ├── 2481.py │ ├── 2481.java │ └── 2481.cpp ├── 2880. Select Data │ └── 2880.py ├── 3028. Ant on the Boundary │ ├── 3028.py │ └── 3028.cpp ├── 3110. Score of a String │ ├── 3110.py │ ├── 3110.cpp │ └── 3110.java ├── 476. Number Complement │ ├── 476.java │ └── 476.cpp ├── 1667. Fix Names in a Table │ └── 1667.sql ├── 2057. Smallest Index With Equal Value │ ├── 2057.py │ ├── 2057.java │ └── 2057.cpp ├── 2229. Check if an Array Is Consecutive │ └── 2229.py ├── 2651. Calculate Delayed Arrival Time │ ├── 2651.py │ ├── 2651.java │ └── 2651.cpp ├── 2729. Check if The Number is Fascinating │ ├── 2729.py │ └── 2729.cpp ├── 2740. Find the Value of the Partition │ └── 2740.py ├── 2833. Furthest Point From Origin │ └── 2833.py ├── 2888. Reshape Data: Concatenate │ └── 2888.py ├── 290. Word Pattern │ └── 290.py ├── 2914. Minimum Number of Changes to Make Binary String Beautiful │ └── 2914.py ├── 2985. Calculate Compressed Mean │ └── 2985.sql ├── 3300. Minimum Element After Replacement With Digit Sum │ └── 3300.py ├── 3456. Find Special Substring of Length K │ └── 3456.py ├── 657. Robot Return to Origin │ └── 657.py ├── 2206. Divide Array Into Equal Pairs │ └── 2206.py ├── 2480. Form a Chemical Bond │ └── 2480.sql ├── 2668. Find Latest Salaries │ └── 2668.sql ├── 2806. Account Balance After Rounded Purchase │ ├── 2806.py │ ├── 2806.java │ └── 2806.cpp ├── 3019. Number of Changing Keys │ └── 3019.py ├── 367. Valid Perfect Square │ └── 367.py ├── 704. Binary Search │ ├── 704.java │ └── 704.py ├── 1238. Circular Permutation in Binary Representation │ └── 1238.py ├── 1518. Water Bottles │ └── 1518-2.cpp ├── 1587. Bank Account Summary II │ └── 1587.sql ├── 168. Excel Sheet Column Title │ ├── 168.java │ ├── 168.py │ └── 168.cpp ├── 1768. Merge Strings Alternately │ └── 1768.py ├── 1941. Check if All Characters Have Equal Number of Occurrences │ └── 1941.py ├── 2545. Sort the Students by Their Kth Score │ ├── 2545.py │ └── 2545.java ├── 2639. Find the Width of Columns of a Grid │ └── 2639.py ├── 2679. Sum in a Matrix │ └── 2679.py ├── 2883. Drop Missing Data │ └── 2883.py ├── 2884. Modify Columns │ └── 2884.py ├── 2887. Fill Missing Data │ └── 2887.py ├── 3083. Existence of a Substring in a String and Its Reverse │ └── 3083.py ├── 3190. Find Minimum Operations to Make All Elements Divisible by Three │ ├── 3190.py │ ├── 3190.java │ └── 3190.cpp ├── 3498. Reverse Degree of a String │ └── 3498.py ├── 512. Game Play Analysis II │ └── 512.sql ├── 574. Winning Candidate │ └── 574.sql ├── 578. Get Highest Answer Rate Question │ └── 578.sql ├── 771. Jewels and Stones │ └── 771.py ├── 899. Orderly Queue │ └── 899.py ├── 1009. Complement of Base 10 Integer │ ├── 1009.py │ ├── 1009.java │ └── 1009.cpp ├── 1791. Find Center of Star Graph │ ├── 1791.py │ └── 1791.java ├── 1859. Sorting the Sentence │ └── 1859.py ├── 1980. Find Unique Binary String │ └── 1980-2.py ├── 2798. Number of Employees Who Met the Target │ ├── 2798.py │ └── 2798.java ├── 2881. Create a New Column │ └── 2881.py ├── 3059. Find All Unique Email Domains │ └── 3059.sql ├── 3084. Count Substrings Starting and Ending with Given Character │ ├── 3084.py │ ├── 3084.java │ └── 3084.cpp ├── 3330. Find the Original Typed String I │ └── 3330.py ├── 1075. Project Employees I │ └── 1075.sql ├── 171. Excel Sheet Column Number │ ├── 171.java │ └── 171.py ├── 1812. Determine Color of a Chessboard Square │ ├── 1812.py │ └── 1812.cpp ├── 1967. Number of Strings That Appear as Substrings in Word │ ├── 1967.py │ └── 1967.java ├── 1988. Find Cutoff Score for Each School │ └── 1988.sql ├── 2011. Final Value of Variable After Performing Operations │ └── 2011.py ├── 2160. Minimum Sum of Four Digit Number After Splitting Digits │ └── 2160.py ├── 268. Missing Number │ ├── 268.py │ ├── 268.java │ └── 268.cpp ├── 2738. Count Occurrences in Text │ └── 2738.sql ├── 3051. Find Candidates for Data Scientist Position │ └── 3051.sql ├── 412. Fizz Buzz │ └── 412.py ├── 869. Reordered Power of 2 │ └── 869.py ├── 1137. N-th Tribonacci Number │ ├── 1137-2.py │ └── 1137-2.java ├── 1211. Queries Quality and Percentage │ └── 1211.sql ├── 1271. Hexspeak │ └── 1271.py ├── 1460. Make Two Arrays Equal by Reversing Subarrays │ └── 1460.py ├── 1484. Group Sold Products By The Date │ └── 1484.sql ├── 1491. Average Salary Excluding the Minimum and Maximum Salary │ └── 1491.py ├── 1619. Mean of Array After Removing Some Elements │ └── 1619.py ├── 1668. Maximum Repeating Substring │ ├── 1668.py │ └── 1668.java ├── 1693. Daily Leads and Partners │ └── 1693.sql ├── 1837. Sum of Digits in Base K │ ├── 1837.py │ ├── 1837.java │ └── 1837.cpp ├── 2129. Capitalize the Title │ └── 2129.py ├── 2308. Arrange Table by Gender │ └── 2308.sql ├── 2339. All the Matches of the League │ └── 2339.sql ├── 2529. Maximum Count of Positive Integer and Negative Integer │ └── 2529.py ├── 2550. Count Collisions of Monkeys on a Polygon │ └── 2550.py ├── 2629. Function Composition │ └── 2629.ts ├── 2690. Infinite Method Object │ └── 2690.ts ├── 2811. Check if it is Possible to Split Array │ └── 2811.py ├── 2877. Create a DataFrame from List │ └── 2877.py ├── 2997. Minimum Number of Operations to Make Array XOR Equal to K │ └── 2997.py ├── 3032. Count Numbers With Unique Digits II │ └── 3032.py ├── 3360. Stone Removal Game │ └── 3360.py ├── 3491. Phone Number Prefix │ └── 3491.py ├── 570. Managers with at Least 5 Direct Reports │ └── 570.sql ├── 1308. Running Total for Different Genders │ └── 1308.sql ├── 1350. Students With Invalid Departments │ └── 1350.sql ├── 1374. Generate a String With Characters That Have Odd Counts │ ├── 1374.py │ └── 1374.cpp ├── 1389. Create Target Array in the Given Order │ └── 1389.py ├── 1543. Fix Product Name Format │ └── 1543.sql ├── 1877. Minimize Maximum Pair Sum in Array │ └── 1877.py ├── 190. Reverse Bits │ └── 190.py ├── 2496. Maximum Value of a String in an Array │ └── 2496.py ├── 2778. Sum of Squares of Special Elements │ └── 2778.py ├── 3513. Number of Unique XOR Triplets I │ └── 3513.py ├── 619. Biggest Single Number │ └── 619.sql ├── 836. Rectangle Overlap │ ├── 836.py │ └── 836.cpp ├── 914. X of a Kind in a Deck of Cards │ └── 914.py ├── 104. Maximum Depth of Binary Tree │ ├── 104.py │ ├── 104.java │ └── 104.cpp ├── 1113. Reported Posts │ └── 1113.sql ├── 1141. User Activity for the Past 30 Days I │ └── 1141.sql ├── 1217. Play with Chips │ ├── 1217.py │ ├── 1217.java │ └── 1217.cpp ├── 1486. XOR Operation in an Array │ ├── 1486.py │ ├── 1486.java │ └── 1486.cpp ├── 1708. Largest Subarray Length K │ ├── 1708.py │ └── 1708.cpp ├── 1720. Decode XORed Array │ └── 1720.py ├── 1874. Minimize Product Sum of Two Arrays │ └── 1874.py ├── 222. Count Complete Tree Nodes │ ├── 222.java │ ├── 222.py │ └── 222.cpp ├── 2268. Minimum Number of Keypresses │ └── 2268.py ├── 2275. Largest Combination With Bitwise AND Greater Than Zero │ └── 2275.py ├── 2427. Number of Common Factors │ └── 2427.py ├── 2500. Delete Greatest Value in Each Row │ └── 2500.py ├── 2587. Rearrange Array to Maximize Prefix Score │ └── 2587.py ├── 2951. Find the Peaks │ └── 2951.py ├── 3223. Minimum Length of String After Operations │ └── 3223.py ├── 3226. Number of Bit Changes to Make Two Integers Equal │ ├── 3226.py │ ├── 3226.java │ └── 3226.cpp ├── 717. 1-bit and 2-bit Characters │ └── 717.py ├── 1133. Largest Unique Number │ └── 1133.py ├── 1407. Top Travellers │ └── 1407.sql ├── 1748. Sum of Unique Elements │ └── 1748.py ├── 181. Employees Earning More Than Their Managers │ └── 181.sql ├── 1844. Replace All Digits with Characters │ ├── 1844.cpp │ └── 1844.py ├── 1934. Confirmation Rate │ └── 1934.sql ├── 2063. Vowels of All Substrings │ └── 2063-2.py ├── 2164. Sort Even and Odd Indices Independently │ └── 2164-2.py ├── 2177. Find Three Consecutive Integers That Sum to a Given Number │ └── 2177.py ├── 2329. Product Sales Analysis V │ └── 2329.sql ├── 2652. Sum Multiples │ ├── 2652.py │ ├── 2652.java │ └── 2652.cpp ├── 2723. Add Two Promises │ └── 2723.ts ├── 2882. Drop Duplicate Rows │ └── 2882.py ├── 2989. Class Performance │ └── 2989.sql ├── 3220. Odd and Even Transactions │ └── 3220.sql ├── 3282. Reach End of Array With Max Score │ └── 3282.py ├── 3289. The Two Sneaky Numbers of Digitville │ └── 3289.py ├── 3379. Transformed Array │ └── 3379.py ├── 3467. Transform Array by Parity │ └── 3467.py ├── 3516. Find Closest Person │ └── 3516.py ├── 775. Global and Local Inversions │ ├── 775-2.py │ └── 775-2.java ├── 1083. Sales Analysis II │ └── 1083.sql ├── 1470. Shuffle the Array │ └── 1470.py ├── 1684. Count the Number of Consistent Strings │ └── 1684.py ├── 1940. Longest Common Subsequence Between Sorted Arrays │ └── 1940-2.py ├── 197. Rising Temperature │ └── 197.sql ├── 2148. Count Elements With Strictly Smaller and Greater Elements │ └── 2148.py ├── 275. H-Index II │ └── 275.py ├── 2828. Check if a String Is an Acronym of Words │ └── 2828.py ├── 2859. Sum of Values at Indices With K Set Bits │ └── 2859.py ├── 3285. Find Indices of Stable Mountains │ └── 3285.py ├── 3295. Report Spam Message │ └── 3295.py ├── 3392. Count Subarrays of Length Three With a Condition │ └── 3392.py ├── 3407. Substring Matching Pattern │ └── 3407.py ├── 344. Reverse String │ ├── 344.cpp │ └── 344.py ├── 3487. Maximum Unique Subarray Sum After Deletion │ └── 3487.py ├── 580. Count Student Number in Departments │ └── 580.sql ├── 612. Shortest Distance in a Plane │ └── 612.sql ├── 628. Maximum Product of Three Numbers │ └── 628.py ├── 728. Self Dividing Numbers │ └── 728.py ├── 1002. Find Common Characters │ └── 1002.py ├── 1699. Number of Calls Between Two Persons │ └── 1699.sql ├── 1780. Check if Number is a Sum of Powers of Three │ └── 1780.py ├── 1903. Largest Odd Number in String │ └── 1903.py ├── 2041. Accepted Candidates From the Interviews │ └── 2041.sql ├── 2066. Account Balance │ └── 2066.sql ├── 2128. Remove All Ones With Row and Column Flips │ └── 2128.py ├── 2244. Minimum Rounds to Complete All Tasks │ └── 2244.py ├── 2506. Count Pairs Of Similar Strings │ └── 2506-2.py ├── 2568. Minimum Impossible OR │ └── 2568.py ├── 2632. Curry │ └── 2632.ts ├── 2686. Immediate Food Delivery III │ └── 2686.sql ├── 2784. Check if Array is Good │ └── 2784.py ├── 2837. Total Traveled Distance │ └── 2837.sql ├── 3000. Maximum Area of Longest Diagonal Rectangle │ └── 3000.py ├── 3205. Maximum Array Hopping Score I │ └── 3205-2.py ├── 372. Super Pow │ └── 372.py ├── 389. Find the Difference │ └── 389-2.py ├── 607. Sales Person │ └── 607.sql ├── 1337. The K Weakest Rows in a Matrix │ └── 1337.py ├── 1607. Sellers With No Sales │ └── 1607.sql ├── 1897. Redistribute Characters to Make All Strings Equal │ └── 1897.py ├── 2154. Keep Multiplying Found Values by Two │ └── 2155.py ├── 2974. Minimum Number Game │ └── 2974.py ├── 3150. Invalid Tweets II │ └── 3150.sql ├── 3172. Second Day Verification │ └── 3172.sql ├── 3415. Find Products with Three Consecutive Digits │ └── 3415.sql ├── 3423. Maximum Difference Between Adjacent Elements in a Circular Array │ └── 3423.py ├── 3465. Find Products with Valid Serial Numbers │ └── 3465.sql ├── 651. 4 Keys Keyboard │ ├── 651.java │ └── 651.cpp ├── 893. Groups of Special-Equivalent Strings │ └── 893.py ├── 1071. Greatest Common Divisor of Strings │ └── 1071-2.py ├── 1426. Counting Elements │ └── 1426.py ├── 1565. Unique Orders and Customers Per Month │ └── 1565.sql ├── 1679. Max Number of K-Sum Pairs │ └── 1679.py ├── 1835. Find XOR Sum of All Pairs Bitwise AND │ └── 1835.py ├── 214. Shortest Palindrome │ └── 214.py ├── 2374. Node With Highest Edge Score │ └── 2374.py ├── 2377. Sort the Olympic Table │ └── 2377.sql ├── 263. Ugly Number │ └── 263.py ├── 27. Remove Element │ ├── 27.py │ ├── 27.java │ └── 27.cpp ├── 2796. Repeat String │ └── 2796.ts ├── 2803. Factorial Generator │ └── 2803.ts ├── 2891. Method Chaining │ └── 2891.py ├── 2979. Most Expensive Item That Can Not Be Bought │ ├── 2979.py │ ├── 2979.java │ └── 2979.cpp ├── 462. Minimum Moves to Equal Array Elements II │ └── 462.py ├── 48. Rotate Image │ └── 48.py ├── 62. Unique Paths │ └── 62-2.py ├── 89. Gray Code │ └── 89.py ├── 1017. Convert to Base -2 │ └── 1017.py ├── 1313. Decompress Run-Length Encoded List │ └── 1313.py ├── 137. Single Number II │ ├── 137.py │ └── 137-2.py ├── 1725. Number Of Rectangles That Can Form The Largest Square │ └── 1725.py ├── 176. Second Highest Salary │ └── 176.sql ├── 1809. Ad-Free Sessions │ └── 1809.sql ├── 2006. Count Number of Pairs With Absolute Difference K │ └── 2006.py ├── 2931. Maximum Spending After Buying Items │ └── 2931.py ├── 3146. Permutation Difference between Two Strings │ └── 3146.py ├── 3194. Minimum Average of Smallest and Largest Elements │ └── 3194.py ├── 3405. Count the Number of Arrays with K Matching Adjacent Elements │ └── 3405.py ├── 461. Hamming Distance │ └── 461.py ├── 528. Random Pick with Weight │ └── 528-2.py ├── 614. Second Degree Follower │ └── 614.sql ├── 884. Uncommon Words from Two Sentences │ └── 884.py ├── 1072. Flip Columns For Maximum Number of Equal Rows │ └── 1072.py ├── 1078. Occurrences After Bigram │ └── 1078.py ├── 1317. Convert Integer to the Sum of Two No-Zero Integers │ └── 1317.py ├── 1715. Count Apples and Oranges │ └── 1715.sql ├── 1732. Find the Highest Altitude │ └── 1732.py ├── 1893. Check if All the Integers in a Range Are Covered │ └── 1893.py ├── 2351. First Letter to Appear Twice │ └── 2351.py ├── 2390. Removing Stars From a String │ └── 2390.py ├── 2418. Sort the People │ └── 2418.py ├── 2619. Array Prototype Last │ └── 2619.ts ├── 2745. Construct the Longest New String │ └── 2745.java ├── 3014. Minimum Number of Pushes to Type Word I │ └── 3014.py ├── 3162. Find the Number of Good Pairs I │ └── 3162.py ├── 559. Maximum Depth of N-ary Tree │ └── 559.py ├── 746. Min Cost Climbing Stairs │ └── 746.py ├── 933. Number of Recent Calls │ └── 933.cpp ├── 1037. Valid Boomerang │ └── 1037.py ├── 1076. Project Employees II │ └── 1076.sql ├── 1158. Market Analysis I │ └── 1158.sql ├── 1250. Check If It Is a Good Array │ └── 1250.cpp ├── 1637. Widest Vertical Area Between Two Points Containing No Points │ └── 1637.py ├── 1957. Delete Characters to Make Fancy String │ └── 1957.py ├── 2180. Count Integers With Even Digit Sum │ └── 2180.py ├── 2215. Find the Difference of Two Arrays │ └── 2215.py ├── 2221. Find Triangular Sum of an Array │ └── 2221.py ├── 2264. Largest 3-Same-Digit Number in String │ └── 2264.py ├── 2283. Check if Number Has Equal Digit Count and Digit Value │ └── 2283.py ├── 2635. Apply Transform Over Each Element in Array │ └── 2635.ts ├── 2636. Promise Pool │ └── 2636.ts ├── 2717. Semi-Ordered Permutation │ └── 2717.py ├── 2890. Reshape Data: Melt │ └── 2890.py ├── 3417. Zigzag Grid Traversal With Skip │ └── 3417.py ├── 387. First Unique Character in a String │ └── 387.py ├── 1290. Convert Binary Number in a Linked List to Integer │ └── 1290.py ├── 1550. Three Consecutive Odds │ └── 1550.py ├── 1558. Minimum Numbers of Function Calls to Make Target Array │ └── 1558.py ├── 2133. Check if Every Row and Column Contains All Numbers │ └── 2133.py ├── 2186. Minimum Number of Steps to Make Two Strings Anagram II │ └── 2186.py ├── 2544. Alternating Digit Sum │ └── 2544.py └── 2605. Form Smallest Number From Two Digit Arrays │ └── 2605.py └── .prettierrc /solutions/2917. Find the K-or of an Array/2917.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /solutions/195. Tenth Line/195.sh: -------------------------------------------------------------------------------- 1 | awk 'NR == 10' file.txt 2 | -------------------------------------------------------------------------------- /solutions/2446. Determine if Two Events Have Conflict/2446.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /solutions/2259. Remove Digit From Number to Maximize Result/2259.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /solutions/2235. Add Two Integers/2235.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | sum = operator.add 3 | -------------------------------------------------------------------------------- /solutions/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/walkccc/LeetCode/HEAD/solutions/.DS_Store -------------------------------------------------------------------------------- /solutions/627. Swap Salary/627.sql: -------------------------------------------------------------------------------- 1 | UPDATE Salary 2 | SET sex = IF(sex = 'm', 'f', 'm'); 3 | -------------------------------------------------------------------------------- /solutions/1683. Invalid Tweets/1683.sql: -------------------------------------------------------------------------------- 1 | SELECT tweet_id 2 | FROM Tweets 3 | WHERE CHAR_LENGTH(content) > 15; 4 | -------------------------------------------------------------------------------- /solutions/182. Duplicate Emails/182.sql: -------------------------------------------------------------------------------- 1 | SELECT email 2 | FROM Person 3 | GROUP BY 1 4 | HAVING COUNT(*) > 1; 5 | -------------------------------------------------------------------------------- /solutions/1853. Convert Date Format/1853.sql: -------------------------------------------------------------------------------- 1 | SELECT DATE_FORMAT(day, '%W, %M %e, %Y') AS day 2 | FROM Days 3 | -------------------------------------------------------------------------------- /solutions/192. Word Frequency/192.sh: -------------------------------------------------------------------------------- 1 | cat words.txt | tr -s ' ' '\n' | sort | uniq -c | sort -r | awk '{ print $2, $1 }' 2 | -------------------------------------------------------------------------------- /solutions/292. Nim Game/292.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def canWinNim(self, n: int) -> bool: 3 | return n % 4 != 0 4 | -------------------------------------------------------------------------------- /solutions/1025. Divisor Game/1025.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def divisorGame(self, n: int) -> bool: 3 | return n % 2 == 0 4 | -------------------------------------------------------------------------------- /solutions/584. Find Customer Referee/584.sql: -------------------------------------------------------------------------------- 1 | SELECT name 2 | FROM Customer 3 | WHERE referee_id IS NULL OR referee_id != 2; 4 | -------------------------------------------------------------------------------- /solutions/596. Classes More Than 5 Students/596.sql: -------------------------------------------------------------------------------- 1 | SELECT class 2 | FROM Courses 3 | GROUP BY 1 4 | HAVING COUNT(*) >= 5; 5 | -------------------------------------------------------------------------------- /solutions/1256. Encode Number/1256.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def encode(self, num: int) -> str: 3 | return bin(num + 1)[3:] 4 | -------------------------------------------------------------------------------- /solutions/178. Rank Scores/178.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | score, 3 | DENSE_RANK() OVER(ORDER BY score DESC) AS `rank` 4 | FROM Scores; 5 | -------------------------------------------------------------------------------- /solutions/511. Game Play Analysis I/511.sql: -------------------------------------------------------------------------------- 1 | SELECT player_id, MIN(event_date) AS first_login 2 | FROM Activity 3 | GROUP BY 1; 4 | -------------------------------------------------------------------------------- /solutions/1069. Product Sales Analysis II/1069.sql: -------------------------------------------------------------------------------- 1 | SELECT product_id, SUM(quantity) AS total_quantity 2 | FROM Sales 3 | GROUP BY 1; 4 | -------------------------------------------------------------------------------- /solutions/191. Number of 1 Bits/191-2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def hammingWeight(self, n: int) -> int: 3 | return n.bit_count() 4 | -------------------------------------------------------------------------------- /solutions/292. Nim Game/292.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool canWinNim(int n) { 4 | return n % 4 != 0; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/292. Nim Game/292.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean canWinNim(int n) { 3 | return n % 4 != 0; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/595. Big Countries/595.sql: -------------------------------------------------------------------------------- 1 | SELECT name, population, area 2 | FROM World 3 | WHERE area >= 3000000 OR population >= 25000000; 4 | -------------------------------------------------------------------------------- /solutions/1025. Divisor Game/1025.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean divisorGame(int n) { 3 | return n % 2 == 0; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/1148. Article Views I/1148.sql: -------------------------------------------------------------------------------- 1 | SELECT DISTINCT author_id AS id 2 | FROM Views 3 | WHERE author_id = viewer_id 4 | ORDER BY 1; 5 | -------------------------------------------------------------------------------- /solutions/1688. Count of Matches in Tournament/1688.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numberOfMatches(self, n: int) -> int: 3 | return n - 1 4 | -------------------------------------------------------------------------------- /solutions/1757. Recyclable and Low Fat Products/1757.sql: -------------------------------------------------------------------------------- 1 | SELECT product_id 2 | FROM Products 3 | WHERE low_fats = 'Y' AND recyclable = 'Y'; 4 | -------------------------------------------------------------------------------- /solutions/258. Add Digits/258.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int addDigits(int num) { 3 | return 1 + (num - 1) % 9; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/1025. Divisor Game/1025.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool divisorGame(int n) { 4 | return n % 2 == 0; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/1303. Find the Team Size/1303.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | employee_id, 3 | COUNT(*) OVER(PARTITION BY team_id) AS team_size 4 | FROM Employee; 5 | -------------------------------------------------------------------------------- /solutions/193. Valid Phone Numbers/193.sh: -------------------------------------------------------------------------------- 1 | grep -e "^[0-9]\{3\}\-[0-9]\{3\}\-[0-9]\{4\}$" -e "^([0-9]\{3\}) [0-9]\{3\}\-[0-9]\{4\}$" file.txt 2 | -------------------------------------------------------------------------------- /solutions/2026. Low-Quality Problems/2026.sql: -------------------------------------------------------------------------------- 1 | SELECT problem_id 2 | FROM Problems 3 | WHERE likes / (likes + dislikes) < 0.6 4 | ORDER BY 1; 5 | -------------------------------------------------------------------------------- /solutions/2082. The Number of Rich Customers/2082.sql: -------------------------------------------------------------------------------- 1 | SELECT COUNT(DISTINCT customer_id) AS rich_count 2 | FROM Store 3 | WHERE amount > 500; 4 | -------------------------------------------------------------------------------- /solutions/2109. Adding Spaces to a String/2109.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string addSpaces(string s, vector& spaces) {} 4 | }; 5 | -------------------------------------------------------------------------------- /solutions/2235. Add Two Integers/2235.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int sum(int num1, int num2) { 3 | return num1 + num2; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/231. Power of Two/231.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPowerOfTwo(self, n: int) -> bool: 3 | return n >= 0 and n.bit_count() == 1 4 | -------------------------------------------------------------------------------- /solutions/2396. Strictly Palindromic Number/2396.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isStrictlyPalindromic(self, n: int) -> bool: 3 | return False 4 | -------------------------------------------------------------------------------- /solutions/258. Add Digits/258.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int addDigits(int num) { 4 | return 1 + (num - 1) % 9; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/258. Add Digits/258.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def addDigits(self, num: int) -> int: 3 | return 0 if num == 0 else 1 + (num - 1) % 9 4 | -------------------------------------------------------------------------------- /solutions/2620. Counter/2620.ts: -------------------------------------------------------------------------------- 1 | function createCounter(n: number): () => number { 2 | return function () { 3 | return n++; 4 | }; 5 | } 6 | -------------------------------------------------------------------------------- /solutions/2687. Bikes Last Time Used/2687.sql: -------------------------------------------------------------------------------- 1 | SELECT bike_number, MAX(end_time) AS end_time 2 | FROM Bikes 3 | GROUP BY 1 4 | ORDER BY 2 DESC; 5 | -------------------------------------------------------------------------------- /solutions/2716. Minimize String Length/2716.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimizedStringLength(self, s: str) -> int: 3 | return len({*s}) 4 | -------------------------------------------------------------------------------- /solutions/326. Power of Three/326.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPowerOfThree(self, n: int) -> bool: 3 | return n > 0 and 3**19 % n == 0 4 | -------------------------------------------------------------------------------- /solutions/434. Number of Segments in a String/434.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countSegments(self, s: str) -> int: 3 | return len(s.split()) 4 | -------------------------------------------------------------------------------- /solutions/613. Shortest Distance in a Line/613.sql: -------------------------------------------------------------------------------- 1 | SELECT MIN(P1.x - P2.x) AS shortest 2 | FROM Point AS P1, Point AS P2 3 | WHERE P1.x > P2.x; 4 | -------------------------------------------------------------------------------- /solutions/2413. Smallest Even Multiple/2413.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def smallestEvenMultiple(self, n: int) -> int: 3 | return n * (n % 2 + 1) 4 | -------------------------------------------------------------------------------- /solutions/2549. Count Distinct Numbers on Board/2549.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def distinctIntegers(self, n: int) -> int: 3 | return max(n - 1, 1) 4 | -------------------------------------------------------------------------------- /solutions/561. Array Partition I/561.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def arrayPairSum(self, nums: list[int]) -> int: 3 | return sum(sorted(nums)[::2]) 4 | -------------------------------------------------------------------------------- /solutions/610. Triangle Judgement/610.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | *, 3 | IF(x + y > z AND x + z > y AND y + z > x, 'Yes', 'No') AS triangle 4 | FROM Triangle; 5 | -------------------------------------------------------------------------------- /solutions/626. Exchange Seats/626.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | ROW_NUMBER() OVER(ORDER BY IF(MOD(id, 2) = 0, id - 1, id + 1)) AS id, 3 | student 4 | FROM Seat; 5 | -------------------------------------------------------------------------------- /solutions/1119. Remove Vowels from a String/1119.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeVowels(self, s: str) -> str: 3 | return re.sub('a|e|i|o|u', '', s) 4 | -------------------------------------------------------------------------------- /solutions/151. Reverse Words in a String/151.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reverseWords(self, s: str) -> str: 3 | return ' '.join(reversed(s.split())) 4 | -------------------------------------------------------------------------------- /solutions/1556. Thousand Separator/1556.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def thousandSeparator(self, n: int) -> str: 3 | return f'{n:,}'.replace(',', '.') 4 | -------------------------------------------------------------------------------- /solutions/1688. Count of Matches in Tournament/1688.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int numberOfMatches(int n) { 3 | return n - 1; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/1816. Truncate Sentence/1816.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def truncateSentence(self, s: str, k: int) -> str: 3 | return ' '.join(s.split()[:k]) 4 | -------------------------------------------------------------------------------- /solutions/191. Number of 1 Bits/191-2.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int hammingWeight(uint32_t n) { 4 | return popcount(n); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/1929. Concatenation of Array/1929.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def getConcatenation(self, nums: list[int]) -> list[int]: 3 | return nums * 2 4 | -------------------------------------------------------------------------------- /solutions/2005. Subtree Removal Game with Fibonacci Tree/2005.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findGameWinner(self, n: int) -> bool: 3 | return n % 6 != 1 4 | -------------------------------------------------------------------------------- /solutions/2124. Check if All A's Appears Before All B's/2124.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def checkString(self, s: str) -> bool: 3 | return 'ba' not in s 4 | -------------------------------------------------------------------------------- /solutions/2235. Add Two Integers/2235.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int sum(int num1, int num2) { 4 | return num1 + num2; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/2579. Count Total Number of Colored Cells/2579.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def coloredCells(self, n: int) -> int: 3 | return n**2 + (n - 1)**2 4 | -------------------------------------------------------------------------------- /solutions/3358. Books with NULL Ratings/3358.sql: -------------------------------------------------------------------------------- 1 | SELECT book_id, title, author, published_year 2 | FROM Books 3 | WHERE rating IS NULL 4 | ORDER BY 1; 5 | -------------------------------------------------------------------------------- /solutions/3436. Find Valid Emails/3436.sql: -------------------------------------------------------------------------------- 1 | SELECT user_id, email 2 | FROM Users 3 | WHERE email REGEXP '^[A-Za-z0-9_]+@[A-Za-z]+\.com$' 4 | ORDER BY 1; 5 | -------------------------------------------------------------------------------- /solutions/441. Arranging Coins/441.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def arrangeCoins(self, n: int) -> int: 3 | return int((-1 + math.sqrt(8 * n + 1)) // 2) 4 | -------------------------------------------------------------------------------- /solutions/1108. Defanging an IP Address/1108.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def defangIPaddr(self, address: str) -> str: 3 | return address.replace('.', '[.]') 4 | -------------------------------------------------------------------------------- /solutions/1323. Maximum 69 Number/1323.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maximum69Number(self, num: int) -> int: 3 | return int(str(num).replace('6', '9', 1)) 4 | -------------------------------------------------------------------------------- /solutions/1445. Apples & Oranges/1445.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | sale_date, 3 | SUM(IF(fruit = 'apples', sold_num, -sold_num)) AS diff 4 | FROM Sales 5 | GROUP BY 1; 6 | -------------------------------------------------------------------------------- /solutions/1517. Find Users With Valid E-Mails/1517.sql: -------------------------------------------------------------------------------- 1 | SELECT * 2 | FROM Users 3 | WHERE REGEXP_LIKE(mail, '^[A-Za-z]+[A-Za-z0-9\_\.\-]*@leetcode\\.com$'); 4 | -------------------------------------------------------------------------------- /solutions/1527. Patients With a Condition/1527.sql: -------------------------------------------------------------------------------- 1 | SELECT * 2 | FROM Patients 3 | WHERE 4 | conditions LIKE 'DIAB1%' 5 | OR conditions LIKE '% DIAB1%'; 6 | -------------------------------------------------------------------------------- /solutions/1688. Count of Matches in Tournament/1688.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numberOfMatches(int n) { 4 | return n - 1; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/1821. Find Customers With Positive Revenue this Year/1821.sql: -------------------------------------------------------------------------------- 1 | SELECT DISTINCT customer_id 2 | FROM Customers 3 | WHERE year = 2021 AND revenue > 0; 4 | -------------------------------------------------------------------------------- /solutions/1908. Game of Nim/1908.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def nimGame(self, piles: list[int]) -> bool: 3 | return functools.reduce(operator.xor, piles) > 0 4 | -------------------------------------------------------------------------------- /solutions/217. Contains Duplicate/217.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def containsDuplicate(self, nums: list[int]) -> bool: 3 | return len(nums) != len(set(nums)) 4 | -------------------------------------------------------------------------------- /solutions/2396. Strictly Palindromic Number/2396.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isStrictlyPalindromic(int n) { 3 | return false; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/2413. Smallest Even Multiple/2413.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int smallestEvenMultiple(int n) { 3 | return n * (n % 2 + 1); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/441. Arranging Coins/441.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int arrangeCoins(long n) { 4 | return (-1 + sqrt(8 * n + 1)) / 2; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/459. Repeated Substring Pattern/459.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def repeatedSubstringPattern(self, s: str) -> bool: 3 | return s in (s + s)[1:-1] 4 | -------------------------------------------------------------------------------- /solutions/507. Perfect Number/507.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def checkPerfectNumber(self, num: int) -> bool: 3 | return num in {6, 28, 496, 8128, 33550336} 4 | -------------------------------------------------------------------------------- /solutions/620. Not Boring Movies/620.sql: -------------------------------------------------------------------------------- 1 | SELECT * 2 | FROM Cinema 3 | WHERE 4 | MOD(id, 2) = 1 5 | AND description != 'boring' 6 | ORDER BY rating DESC; 7 | -------------------------------------------------------------------------------- /solutions/660. Remove 9/660.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int newInteger(int n) { 3 | return Integer.parseInt(Integer.toString(n, 9)); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/1304. Find N Unique Integers Sum up to Zero/1304.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sumZero(self, n: int) -> list[int]: 3 | return list(range(1 - n, n, 2)) 4 | -------------------------------------------------------------------------------- /solutions/1332. Remove Palindromic Subsequences/1332.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removePalindromeSub(self, s: str) -> int: 3 | return 1 if s == s[::-1] else 2 4 | -------------------------------------------------------------------------------- /solutions/136. Single Number/136.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def singleNumber(self, nums: list[int]) -> int: 3 | return functools.reduce(operator.xor, nums, 0) 4 | -------------------------------------------------------------------------------- /solutions/1480. Running Sum of 1d Array/1480.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def runningSum(self, nums: list[int]) -> list[int]: 3 | return itertools.accumulate(nums) 4 | -------------------------------------------------------------------------------- /solutions/1729. Find Followers Count/1729.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | user_id, 3 | COUNT(follower_id) AS followers_count 4 | FROM Followers 5 | GROUP BY 1 6 | ORDER BY 1; 7 | -------------------------------------------------------------------------------- /solutions/196. Delete Duplicate Emails/196.sql: -------------------------------------------------------------------------------- 1 | DELETE P2 2 | FROM Person AS P1 3 | INNER JOIN Person AS P2 4 | ON (P1.email = P2.email) 5 | WHERE P1.id < P2.id; 6 | -------------------------------------------------------------------------------- /solutions/231. Power of Two/231.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isPowerOfTwo(int n) { 3 | return n >= 0 && Integer.bitCount(n) == 1; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/2396. Strictly Palindromic Number/2396.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isStrictlyPalindromic(int n) { 4 | return false; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/2413. Smallest Even Multiple/2413.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int smallestEvenMultiple(int n) { 4 | return n * (n % 2 + 1); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/2710. Remove Trailing Zeros From a String/2710.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeTrailingZeros(self, num: str) -> str: 3 | return num.rstrip('0') 4 | -------------------------------------------------------------------------------- /solutions/326. Power of Three/326.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isPowerOfThree(int n) { 3 | return n > 0 && Math.pow(3, 19) % n == 0; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/3370. Smallest Number With All Set Bits/3370.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def smallestNumber(self, n: int) -> int: 3 | return (1 << n.bit_length()) - 1 4 | -------------------------------------------------------------------------------- /solutions/441. Arranging Coins/441.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int arrangeCoins(long n) { 3 | return (int) (-1 + Math.sqrt(8 * n + 1)) / 2; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/551. Student Attendance Record I/551.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def checkRecord(self, s: str) -> bool: 3 | return s.count('A') <= 1 and 'LLL' not in s 4 | -------------------------------------------------------------------------------- /solutions/586. Customer Placing the Largest Number of Orders/586.sql: -------------------------------------------------------------------------------- 1 | SELECT customer_number 2 | FROM Orders 3 | GROUP BY 1 4 | ORDER BY COUNT(*) DESC 5 | LIMIT 1; 6 | -------------------------------------------------------------------------------- /solutions/796. Rotate String/796.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def rotateString(self, s: str, goal: str) -> bool: 3 | return len(s) == len(goal) and goal in s + s 4 | -------------------------------------------------------------------------------- /solutions/1227. Airplane Seat Assignment Probability/1227.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def nthPersonGetsNthSeat(self, n: int) -> float: 3 | return 1 if n == 1 else 0.5 4 | -------------------------------------------------------------------------------- /solutions/1256. Encode Number/1256.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String encode(int num) { 3 | return Integer.toBinaryString(num + 1).substring(1); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/1393. Capital Gain/Loss/1393.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | stock_name, 3 | SUM(IF(operation = 'Buy', -price, price)) AS capital_gain_loss 4 | FROM Stocks 5 | GROUP BY 1; 6 | -------------------------------------------------------------------------------- /solutions/1672. Richest Customer Wealth/1672.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maximumWealth(self, accounts: list[list[int]]) -> int: 3 | return max(map(sum, accounts)) 4 | -------------------------------------------------------------------------------- /solutions/1689. Partitioning Into Minimum Number Of Deci-Binary Numbers/1689.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minPartitions(self, n: str) -> int: 3 | return int(max(n)) 4 | -------------------------------------------------------------------------------- /solutions/1832. Check if the Sentence Is Pangram/1832.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def checkIfPangram(self, sentence: str) -> bool: 3 | return len(set(sentence)) == 26 4 | -------------------------------------------------------------------------------- /solutions/2005. Subtree Removal Game with Fibonacci Tree/2005.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean findGameWinner(int n) { 3 | return n % 6 != 1; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/205. Isomorphic Strings/205.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isIsomorphic(self, s: str, t: str) -> bool: 3 | return [*map(s.index, s)] == [*map(t.index, t)] 4 | -------------------------------------------------------------------------------- /solutions/2119. A Number After a Double Reversal/2119-2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isSameAfterReversals(self, num: int) -> bool: 3 | return num == 0 or num % 10 4 | -------------------------------------------------------------------------------- /solutions/231. Power of Two/231.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isPowerOfTwo(int n) { 4 | return n >= 0 && __builtin_popcount(n) == 1; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/237. Delete Node in a Linked List/237.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def deleteNode(self, node): 3 | node.val = node.next.val 4 | node.next = node.next.next 5 | -------------------------------------------------------------------------------- /solutions/2527. Find Xor-Beauty of Array/2527.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def xorBeauty(self, nums: list[int]) -> int: 3 | return functools.reduce(operator.xor, nums) 4 | -------------------------------------------------------------------------------- /solutions/2549. Count Distinct Numbers on Board/2549.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int distinctIntegers(int n) { 4 | return max(n - 1, 1); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/2549. Count Distinct Numbers on Board/2549.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int distinctIntegers(int n) { 3 | return Math.max(n - 1, 1); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/2667. Create Hello World Function/2667.ts: -------------------------------------------------------------------------------- 1 | function createHelloWorld() { 2 | return function (..._): string { 3 | return 'Hello World'; 4 | }; 5 | } 6 | -------------------------------------------------------------------------------- /solutions/2769. Find the Maximum Achievable Number/2769.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def theMaximumAchievableX(self, num: int, t: int) -> int: 3 | return num + 2 * t 4 | -------------------------------------------------------------------------------- /solutions/2987. Find Expensive Cities/2987.sql: -------------------------------------------------------------------------------- 1 | SELECT city 2 | FROM Listings 3 | GROUP BY 1 4 | HAVING AVG(price) > (SELECT AVG(price) FROM Listings) 5 | ORDER BY 1; 6 | -------------------------------------------------------------------------------- /solutions/1119. Remove Vowels from a String/1119.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String removeVowels(String s) { 3 | return s.replaceAll("[aeiou]", ""); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/1421. NPV Queries/1421.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | Queries.id, 3 | Queries.year, 4 | IFNULL(NPV.npv, 0) AS npv 5 | FROM Queries 6 | LEFT JOIN NPV 7 | USING (id, year); 8 | -------------------------------------------------------------------------------- /solutions/1784. Check if Binary String Has at Most One Segment of Ones/1784.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def checkOnesSegment(self, s: str) -> bool: 3 | return '01' not in s 4 | -------------------------------------------------------------------------------- /solutions/1890. The Latest Login in 2020/1890.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | user_id, 3 | MAX(time_stamp) AS last_stamp 4 | FROM Logins 5 | WHERE YEAR(time_stamp) = 2020 6 | GROUP BY 1; 7 | -------------------------------------------------------------------------------- /solutions/1979. Find Greatest Common Divisor of Array/1979.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findGCD(self, nums: list[int]) -> int: 3 | return math.gcd(min(nums), max(nums)) 4 | -------------------------------------------------------------------------------- /solutions/2005. Subtree Removal Game with Fibonacci Tree/2005.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool findGameWinner(int n) { 4 | return n % 6 != 1; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/2356. Number of Unique Subjects Taught by Each Teacher/2356.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | teacher_id, 3 | COUNT(DISTINCT subject_id) AS cnt 4 | FROM Teacher 5 | GROUP BY 1; 6 | -------------------------------------------------------------------------------- /solutions/2878. Get the Size of a DataFrame/2878.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | 4 | def getDataframeSize(players: pd.DataFrame) -> list[int]: 5 | return [*players.shape] 6 | -------------------------------------------------------------------------------- /solutions/3210. Find the Encrypted String/3210.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def getEncryptedString(self, s: str, k: int) -> str: 3 | k %= len(s) 4 | return s[k:] + s[0:k] 5 | -------------------------------------------------------------------------------- /solutions/520. Detect Capital/520.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def detectCapitalUse(self, word: str) -> bool: 3 | return word.isupper() or word.islower() or word.istitle() 4 | -------------------------------------------------------------------------------- /solutions/577. Employee Bonus/577.sql: -------------------------------------------------------------------------------- 1 | SELECT Employee.name, Bonus.bonus 2 | FROM Employee 3 | LEFT JOIN Bonus 4 | USING (empId) 5 | WHERE IFNULL(Bonus.bonus, 0) < 1000; 6 | -------------------------------------------------------------------------------- /solutions/908. Smallest Range I/908.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def smallestRangeI(self, nums: list[int], k: int) -> int: 3 | return max(0, max(nums) - min(nums) - 2 * k) 4 | -------------------------------------------------------------------------------- /solutions/1050. Actors and Directors Who Cooperated At Least Three Times/1050.sql: -------------------------------------------------------------------------------- 1 | SELECT actor_id, director_id 2 | FROM ActorDirector 3 | GROUP BY 1, 2 4 | HAVING COUNT(*) >= 3; 5 | -------------------------------------------------------------------------------- /solutions/1108. Defanging an IP Address/1108.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String defangIPaddr(String address) { 3 | return address.replace(".", "[.]"); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/1227. Airplane Seat Assignment Probability/1227.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public double nthPersonGetsNthSeat(int n) { 3 | return n == 1 ? 1 : 0.5; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/1678. Goal Parser Interpretation/1678.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def interpret(self, command: str) -> str: 3 | return command.replace('()', 'o').replace('(al)', 'al') 4 | -------------------------------------------------------------------------------- /solutions/172. Factorial Trailing Zeroes/172.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def trailingZeroes(self, n: int) -> int: 3 | return 0 if n == 0 else n // 5 + self.trailingZeroes(n // 5) 4 | -------------------------------------------------------------------------------- /solutions/2124. Check if All A's Appears Before All B's/2124.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean checkString(String s) { 3 | return !s.contains("ba"); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/2220. Minimum Bit Flips to Convert Number/2220.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minBitFlips(self, start: int, goal: int) -> int: 3 | return (start ^ goal).bit_count() 4 | -------------------------------------------------------------------------------- /solutions/2278. Percentage of Letter in String/2278.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def percentageLetter(self, s: str, letter: str) -> int: 3 | return 100 * s.count(letter) // len(s) 4 | -------------------------------------------------------------------------------- /solutions/2298. Tasks Count in the Weekend/2298.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | SUM(WEEKDAY(submit_date) >= 5) AS weekend_cnt, 3 | SUM(WEEKDAY(submit_date) < 5) AS working_cnt 4 | FROM Tasks; 5 | -------------------------------------------------------------------------------- /solutions/2357. Make Array Zero by Subtracting Equal Amounts/2357.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumOperations(self, nums: list[int]) -> int: 3 | return len(set(nums) - {0}) 4 | -------------------------------------------------------------------------------- /solutions/2520. Count the Digits That Divide a Number/2520.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countDigits(self, num: int) -> int: 3 | return sum(num % int(d) == 0 for d in str(num)) 4 | -------------------------------------------------------------------------------- /solutions/2621. Sleep/2621.ts: -------------------------------------------------------------------------------- 1 | async function sleep(millis: number): Promise { 2 | return new Promise((resolve) => { 3 | setTimeout(resolve, millis); 4 | }); 5 | } 6 | -------------------------------------------------------------------------------- /solutions/2769. Find the Maximum Achievable Number/2769.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int theMaximumAchievableX(int num, int t) { 3 | return num + 2 * t; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/2802. Find The K-th Lucky Number/2802.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def kthLuckyNumber(self, k: int) -> str: 3 | return bin(k + 1)[3:].replace('0', '4').replace('1', '7') 4 | -------------------------------------------------------------------------------- /solutions/2879. Display the First Three Rows/2879.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | 4 | def selectFirstRows(employees: pd.DataFrame) -> pd.DataFrame: 5 | return employees.head(3) 6 | -------------------------------------------------------------------------------- /solutions/2886. Change Data Type/2886.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | 4 | def changeDatatype(students: pd.DataFrame) -> pd.DataFrame: 5 | return students.astype({'grade': int}) 6 | -------------------------------------------------------------------------------- /solutions/3204. Bitwise User Permissions Analysis/3204.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | BIT_AND(permissions) AS common_perms, 3 | BIT_OR(permissions) AS any_perms 4 | FROM user_permissions; 5 | -------------------------------------------------------------------------------- /solutions/3536. Maximum Product of Two Digits/3536.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxProduct(self, n: int) -> int: 3 | s = sorted(str(n)) 4 | return int(s[-1]) * int(s[-2]) 5 | -------------------------------------------------------------------------------- /solutions/390. Elimination Game/390.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int lastRemaining(int n) { 3 | return n == 1 ? 1 : 2 * (1 + n / 2 - lastRemaining(n / 2)); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/390. Elimination Game/390.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def lastRemaining(self, n: int) -> int: 3 | return 1 if n == 1 else 2 * (1 + n // 2 - self.lastRemaining(n // 2)) 4 | -------------------------------------------------------------------------------- /solutions/521. Longest Uncommon Subsequence I/521.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findLUSlength(self, a: str, b: str) -> int: 3 | return -1 if a == b else max(len(a), len(b)) 4 | -------------------------------------------------------------------------------- /solutions/575. Distribute Candies/575.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def distributeCandies(self, candies: list[int]) -> int: 3 | return min(len(candies) // 2, len(set(candies))) 4 | -------------------------------------------------------------------------------- /solutions/709. To Lower Case/709.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def toLowerCase(self, str: str) -> str: 3 | return ''.join(chr(ord(c) + 32) if 'A' <= c <= 'Z' else c for c in str) 4 | -------------------------------------------------------------------------------- /solutions/1068. Product Sales Analysis I/1068.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | Product.product_name, 3 | Sales.year, 4 | Sales.price 5 | FROM Sales 6 | INNER JOIN Product 7 | USING (product_id); 8 | -------------------------------------------------------------------------------- /solutions/1149. Article Views II/1149.sql: -------------------------------------------------------------------------------- 1 | SELECT DISTINCT viewer_id AS id 2 | FROM Views 3 | GROUP BY viewer_id, view_date 4 | HAVING COUNT(DISTINCT article_id) > 1 5 | ORDER BY 1; 6 | -------------------------------------------------------------------------------- /solutions/1227. Airplane Seat Assignment Probability/1227.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | double nthPersonGetsNthSeat(int n) { 4 | return n == 1 ? 1 : 0.5; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/1561. Maximum Number of Coins You Can Get/1561.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxCoins(self, piles: list[int]) -> int: 3 | return sum(sorted(piles)[len(piles) // 3::2]) 4 | -------------------------------------------------------------------------------- /solutions/172. Factorial Trailing Zeroes/172.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int trailingZeroes(int n) { 3 | return n == 0 ? 0 : n / 5 + trailingZeroes(n / 5); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/1873. Calculate Special Bonus/1873.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | employee_id, 3 | IF(employee_id % 2 = 1 AND LEFT(name, 1) != 'M', salary, 0) AS bonus 4 | FROM Employees 5 | ORDER BY 1; 6 | -------------------------------------------------------------------------------- /solutions/2119. A Number After a Double Reversal/2119-2.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isSameAfterReversals(int num) { 4 | return num == 0 || num % 10; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/2236. Root Equals Sum of Children/2236.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def checkTree(self, root: TreeNode | None) -> bool: 3 | return root.val == root.left.val + root.right.val 4 | -------------------------------------------------------------------------------- /solutions/2255. Count Prefixes of a Given String/2255.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countPrefixes(self, words: list[str], s: str) -> int: 3 | return sum(map(s.startswith, words)) 4 | -------------------------------------------------------------------------------- /solutions/2335. Minimum Amount of Time to Fill Cups/2335.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def fillCups(self, amount: list[int]) -> int: 3 | return max(max(amount), (sum(amount) + 1) // 2) 4 | -------------------------------------------------------------------------------- /solutions/2469. Convert the Temperature/2469.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def convertTemperature(self, celsius: float) -> list[float]: 3 | return [celsius + 273.15, celsius * 1.8 + 32] 4 | -------------------------------------------------------------------------------- /solutions/2504. Concatenate the Name and the Profession/2504.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | person_id, 3 | CONCAT(name, '(', LEFT(profession, 1), ')') name 4 | FROM Person 5 | ORDER BY 1 DESC; 6 | -------------------------------------------------------------------------------- /solutions/2579. Count Total Number of Colored Cells/2579.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public long coloredCells(int n) { 3 | return 1L * n * n + 1L * (n - 1) * (n - 1); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/2656. Maximum Sum With Exactly K Elements/2656.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maximizeSum(self, nums: list[int], k: int) -> int: 3 | return max(nums) * k + k * (k - 1) // 2 4 | -------------------------------------------------------------------------------- /solutions/2669. Count Artist Occurrences On Spotify Ranking List/2669.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | artist, 3 | COUNT(id) AS occurrences 4 | FROM Spotify 5 | GROUP BY 1 6 | ORDER BY 2 DESC, 1; 7 | -------------------------------------------------------------------------------- /solutions/2733. Neither Minimum nor Maximum/2733.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findNonMinOrMax(self, nums: list[int]) -> int: 3 | return -1 if len(nums) < 3 else sorted(nums[:3])[1] 4 | -------------------------------------------------------------------------------- /solutions/2769. Find the Maximum Achievable Number/2769.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int theMaximumAchievableX(int num, int t) { 4 | return num + 2 * t; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/2923. Find Champion I/2923-2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findChampion(self, grid: list[list[int]]) -> int: 3 | return max(range(len(grid)), key=lambda x: sum(grid[x])) 4 | -------------------------------------------------------------------------------- /solutions/3151. Special Array I/3151.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isArraySpecial(self, nums: list[int]) -> bool: 3 | return all(a % 2 != b % 2 for a, b in itertools.pairwise(nums)) 4 | -------------------------------------------------------------------------------- /solutions/3198. Find Cities in Each State/3198.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | state, 3 | GROUP_CONCAT(city ORDER BY city SEPARATOR ', ') AS cities 4 | FROM Cities 5 | GROUP BY 1 6 | ORDER BY 1; 7 | -------------------------------------------------------------------------------- /solutions/326. Power of Three/326.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isPowerOfThree(int n) { 4 | return n > 0 && static_cast(pow(3, 19)) % n == 0; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/3304. Find the K-th Character in String Game I/3304.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def kthCharacter(self, k: int) -> str: 3 | return string.ascii_lowercase[(k - 1).bit_count()] 4 | -------------------------------------------------------------------------------- /solutions/3353. Minimum Total Operations/3353.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minOperations(self, nums: list[int]) -> int: 3 | return sum(a != b for a, b in itertools.pairwise(nums)) 4 | -------------------------------------------------------------------------------- /solutions/3492. Maximum Containers on a Ship/3492.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxContainers(self, n: int, w: int, maxWeight: int) -> int: 3 | return min(n * n, maxWeight // w) 4 | -------------------------------------------------------------------------------- /solutions/3512. Minimum Operations to Make Array Sum Divisible by K/3512.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minOperations(self, nums: list[int], k: int) -> int: 3 | return sum(nums) % k 4 | -------------------------------------------------------------------------------- /solutions/3560. Find Minimum Log Transportation Cost/3560.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minCuttingCost(self, n: int, m: int, k: int) -> int: 3 | return max(0, max(n, m) - k) * k 4 | -------------------------------------------------------------------------------- /solutions/1085. Sum of Digits in the Minimum Number/1085.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sumOfDigits(self, nums: list[int]) -> int: 3 | return sum(int(d) for d in str(min(nums))) & 1 ^ 1 4 | -------------------------------------------------------------------------------- /solutions/1641. Count Sorted Vowel Strings/1641-2.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int countVowelStrings(int n) { 3 | return (n + 4) * (n + 3) * (n + 2) * (n + 1) / 24; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/172. Factorial Trailing Zeroes/172.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int trailingZeroes(int n) { 4 | return n == 0 ? 0 : n / 5 + trailingZeroes(n / 5); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/1908. Game of Nim/1908.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean nimGame(int[] piles) { 3 | return Arrays.stream(piles).reduce((a, b) -> a ^ b).getAsInt() > 0; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/2119. A Number After a Double Reversal/2119-2.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isSameAfterReversals(int num) { 3 | return num == 0 || num % 10 > 0; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/2124. Check if All A's Appears Before All B's/2124.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool checkString(string s) { 4 | return s.find("ba") == string::npos; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/2678. Number of Senior Citizens/2678.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countSeniors(self, details: list[str]) -> int: 3 | return sum(int(detail[11:13]) > 60 for detail in details) 4 | -------------------------------------------------------------------------------- /solutions/2683. Neighboring Bitwise XOR/2683.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def doesValidArrayExist(self, derived: list[int]) -> bool: 3 | return functools.reduce(operator.xor, derived) == 0 4 | -------------------------------------------------------------------------------- /solutions/2710. Remove Trailing Zeros From a String/2710.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String removeTrailingZeros(String num) { 3 | return num.replaceAll("0+$", ""); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/2864. Maximum Odd Binary Number/2864.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maximumOddBinaryNumber(self, s: str) -> str: 3 | return '1' * (s.count('1') - 1) + '0' * s.count('0') + '1' 4 | -------------------------------------------------------------------------------- /solutions/2990. Loan Types/2990.sql: -------------------------------------------------------------------------------- 1 | SELECT user_id 2 | FROM Loans 3 | WHERE loan_type IN ('Refinance', 'Mortgage') 4 | GROUP BY 1 5 | HAVING COUNT(DISTINCT loan_type) = 2 6 | ORDER BY 1; 7 | -------------------------------------------------------------------------------- /solutions/3131. Find the Integer Added to Array I/3131.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def addedInteger(self, nums1: list[int], nums2: list[int]) -> int: 3 | return min(nums2) - min(nums1) 4 | -------------------------------------------------------------------------------- /solutions/3173. Bitwise OR of Adjacent Elements/3173.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def orArray(self, nums: list[int]) -> list[int]: 3 | return [a | b for a, b in itertools.pairwise(nums)] 4 | -------------------------------------------------------------------------------- /solutions/3304. Find the K-th Character in String Game I/3304.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | char kthCharacter(unsigned k) { 4 | return 'a' + popcount(k - 1); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/3502. Minimum Cost to Reach Every Position/3502.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minCosts(self, cost: list[int]) -> list[int]: 3 | return list(itertools.accumulate(cost, min)) 4 | -------------------------------------------------------------------------------- /solutions/390. Elimination Game/390.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int lastRemaining(int n) { 4 | return n == 1 ? 1 : 2 * (1 + n / 2 - lastRemaining(n / 2)); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/810. Chalkboard XOR Game/810.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def xorGame(self, nums: list[int]) -> bool: 3 | return functools.reduce(operator.xor, nums) == 0 or len(nums) % 2 == 0 4 | -------------------------------------------------------------------------------- /solutions/1134. Armstrong Number/1134.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isArmstrong(self, n: int) -> bool: 3 | s = str(n) 4 | k = len(s) 5 | return sum(pow(int(c), k) for c in s) == n 6 | -------------------------------------------------------------------------------- /solutions/1173. Immediate Food Delivery I/1173.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | ROUND( 3 | 100 * AVG(order_date = customer_pref_delivery_date), 4 | 2 5 | ) AS immediate_percentage 6 | FROM Delivery; 7 | -------------------------------------------------------------------------------- /solutions/1378. Replace Employee ID With The Unique Identifier/1378.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | EmployeeUNI.unique_id, 3 | Employees.name 4 | FROM Employees 5 | LEFT JOIN EmployeeUNI 6 | USING (id); 7 | -------------------------------------------------------------------------------- /solutions/1523. Count Odd Numbers in an Interval Range/1523.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int countOdds(int low, int high) { 4 | return (high + 1) / 2 - low / 2; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/1641. Count Sorted Vowel Strings/1641-2.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int countVowelStrings(int n) { 4 | return (n + 4) * (n + 3) * (n + 2) * (n + 1) / 24; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/1741. Find Total Time Spent by Each Employee/1741.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | event_day AS day, 3 | emp_id, 4 | SUM(out_time - in_time) AS total_time 5 | FROM Employees 6 | GROUP BY 1, 2; 7 | -------------------------------------------------------------------------------- /solutions/1863. Sum of All Subset XOR Totals/1863-2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def subsetXORSum(self, nums: list[int]) -> int: 3 | return functools.reduce(operator.or_, nums) << len(nums) - 1 4 | -------------------------------------------------------------------------------- /solutions/2000. Reverse Prefix of Word/2000.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reversePrefix(self, word: str, ch: str) -> str: 3 | i = word.find(ch) + 1 4 | return word[:i][::-1] + word[i:] 5 | -------------------------------------------------------------------------------- /solutions/2144. Minimum Cost of Buying Candies With Discount/2144.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumCost(self, cost: list[int]) -> int: 3 | return sum(cost) - sum(sorted(cost)[-3::-3]) 4 | -------------------------------------------------------------------------------- /solutions/2214. Minimum Health to Beat Game/2214.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumHealth(self, damage: list[int], armor: int) -> int: 3 | return 1 + sum(damage) - min(max(damage), armor) 4 | -------------------------------------------------------------------------------- /solutions/2220. Minimum Bit Flips to Convert Number/2220.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minBitFlips(int start, int goal) { 3 | return Integer.bitCount(start ^ goal); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/2236. Root Equals Sum of Children/2236.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean checkTree(TreeNode root) { 3 | return root.val == root.left.val + root.right.val; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/2527. Find Xor-Beauty of Array/2527.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int xorBeauty(int[] nums) { 3 | return Arrays.stream(nums).reduce((a, b) -> a ^ b).getAsInt(); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/2543. Check if Point Is Reachable/2543.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isReachable(self, targetX: int, targetY: int) -> bool: 3 | return math.gcd(targetX, targetY).bit_count() == 1 4 | -------------------------------------------------------------------------------- /solutions/2546. Apply Bitwise Operations to Make Strings Equal/2546.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def makeStringsEqual(self, s: str, target: str) -> bool: 3 | return ('1' in s) == ('1' in target) 4 | -------------------------------------------------------------------------------- /solutions/2553. Separate the Digits in an Array/2553.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def separateDigits(self, nums: list[int]) -> list[int]: 3 | return [int(c) for num in nums for c in str(num)] 4 | -------------------------------------------------------------------------------- /solutions/2578. Split With Minimum Sum/2578.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def splitNum(self, num: int) -> int: 3 | s = ''.join(sorted(str(num))) 4 | return sum(map(int, (s[::2], s[1::2]))) 5 | -------------------------------------------------------------------------------- /solutions/2716. Minimize String Length/2716.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minimizedStringLength(string s) { 4 | return unordered_set(s.begin(), s.end()).size(); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/2893. Calculate Orders Within Each Interval/2893.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | CEIL(minute / 6) AS interval_no, 3 | SUM(order_count) AS total_orders 4 | FROM Orders 5 | GROUP BY 1 6 | ORDER BY 1; 7 | -------------------------------------------------------------------------------- /solutions/2980. Check if Bitwise OR Has Trailing Zeros/2980.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def hasTrailingZeros(self, nums: list[int]) -> bool: 3 | return sum(num % 2 == 0 for num in nums) >= 2 4 | -------------------------------------------------------------------------------- /solutions/3046. Split the Array/3046.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPossibleToSplit(self, nums: list[int]) -> bool: 3 | return all(freq <= 2 for freq in collections.Counter(nums).values()) 4 | -------------------------------------------------------------------------------- /solutions/3065. Minimum Operations to Exceed Threshold Value I/3065.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minOperations(self, nums: list[int], k: int) -> int: 3 | return sum(num < k for num in nums) 4 | -------------------------------------------------------------------------------- /solutions/3179. Find the N-th Value After K Seconds/3179.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def valueAfterKSeconds(self, n: int, k: int) -> int: 3 | return math.comb(n + k - 1, n - 1) % 1_000_000_007 4 | -------------------------------------------------------------------------------- /solutions/3222. Find the Winning Player in Coin Game/3222.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def losingPlayer(self, x: int, y: int) -> str: 3 | return 'Bob' if min(x, y // 4) % 2 == 0 else 'Alice' 4 | -------------------------------------------------------------------------------- /solutions/3232. Find if Digit Game Can Be Won/3232.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def canAliceWin(self, nums: list[int]) -> bool: 3 | return sum(num if num < 10 else -num for num in nums) != 0 4 | -------------------------------------------------------------------------------- /solutions/3304. Find the K-th Character in String Game I/3304.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public char kthCharacter(int k) { 3 | return (char) ('a' + Integer.bitCount(k - 1)); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/3340. Check Balanced String/3340.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isBalanced(self, num: str) -> bool: 3 | nums = list(map(int, num)) 4 | return sum(nums[::2]) == sum(nums[1::2]) 5 | -------------------------------------------------------------------------------- /solutions/3492. Maximum Containers on a Ship/3492.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maxContainers(int n, int w, int maxWeight) { 3 | return Math.min(n * n, maxWeight / w); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/453. Minimum Moves to Equal Array Elements/453.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minMoves(self, nums: list[int]) -> int: 3 | mn = min(nums) 4 | return sum(num - mn for num in nums) 5 | -------------------------------------------------------------------------------- /solutions/541. Reverse String II/541.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reverseStr(self, s: str, k: int) -> str: 3 | return s[:k][::-1] + s[k:2 * k] + self.reverseStr(s[2 * k:], k) if s else "" 4 | -------------------------------------------------------------------------------- /solutions/69. Sqrt(x)/69.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def mySqrt(self, x: int) -> int: 3 | return bisect.bisect_right(range(x + 1), x, 4 | key=lambda m: m * m) - 1 5 | -------------------------------------------------------------------------------- /solutions/1045. Customers Who Bought All Products/1045.sql: -------------------------------------------------------------------------------- 1 | SELECT customer_id 2 | FROM Customer 3 | GROUP BY 1 4 | HAVING COUNT(DISTINCT product_key) = ( 5 | SELECT COUNT(*) FROM Product 6 | ); 7 | -------------------------------------------------------------------------------- /solutions/1108. Defanging an IP Address/1108.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string defangIPaddr(string address) { 4 | return regex_replace(address, regex("[.]"), "[.]"); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/1356. Sort Integers by The Number of 1 Bits/1356.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sortByBits(self, arr: list[int]) -> list[int]: 3 | return sorted(arr, key=lambda x: (x.bit_count(), x)) 4 | -------------------------------------------------------------------------------- /solutions/1689. Partitioning Into Minimum Number Of Deci-Binary Numbers/1689.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minPartitions(string n) { 4 | return ranges::max(n) - '0'; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/175. Combine Two Tables/175.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | Person.firstName, 3 | Person.lastName, 4 | Address.city, 5 | Address.state 6 | FROM Person 7 | LEFT JOIN Address 8 | USING (personId); 9 | -------------------------------------------------------------------------------- /solutions/1784. Check if Binary String Has at Most One Segment of Ones/1784.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean checkOnesSegment(String s) { 3 | return !s.contains("01"); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/1805. Number of Different Integers in a String/1805-2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numDifferentIntegers(self, word: str) -> int: 3 | return len(set(map(int, re.findall(r'\d+', word)))) 4 | -------------------------------------------------------------------------------- /solutions/183. Customers Who Never Order/183.sql: -------------------------------------------------------------------------------- 1 | SELECT Customers.name AS Customers 2 | FROM Customers 3 | LEFT JOIN Orders 4 | ON (Customers.id = Orders.customerId) 5 | WHERE Orders.id IS NULL; 6 | -------------------------------------------------------------------------------- /solutions/1908. Game of Nim/1908.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool nimGame(vector& piles) { 4 | return accumulate(piles.begin(), piles.end(), 0, bit_xor<>()) > 0; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/191. Number of 1 Bits/191-2.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | // You need to treat n as an unsigned value 3 | public int hammingWeight(int n) { 4 | return Integer.bitCount(n); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /solutions/201. Bitwise AND of Numbers Range/201.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def rangeBitwiseAnd(self, m: int, n: int) -> int: 3 | return self.rangeBitwiseAnd(m >> 1, n >> 1) << 1 if m < n else m 4 | -------------------------------------------------------------------------------- /solutions/2114. Maximum Number of Words Found in Sentences/2114.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def mostWordsFound(self, sentences: list[str]) -> int: 3 | return max(s.count(' ') for s in sentences) + 1 4 | -------------------------------------------------------------------------------- /solutions/2185. Counting Words With a Given Prefix/2185.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def prefixCount(self, words: list[str], pref: str) -> int: 3 | return sum(word.startswith(pref) for word in words) 4 | -------------------------------------------------------------------------------- /solutions/2220. Minimum Bit Flips to Convert Number/2220.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minBitFlips(unsigned start, unsigned goal) { 4 | return popcount(start ^ goal); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/2239. Find Closest Number to Zero/2239.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findClosestNumber(self, nums: list[int]) -> int: 3 | nums.sort(key=lambda x: (abs(x), -x)) 4 | return nums[0] 5 | -------------------------------------------------------------------------------- /solutions/237. Delete Node in a Linked List/237.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public void deleteNode(ListNode node) { 3 | node.val = node.next.val; 4 | node.next = node.next.next; 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /solutions/2481. Minimum Cuts to Divide a Circle/2481.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numberOfCuts(self, n: int) -> int: 3 | if n == 1: 4 | return 0 5 | return n // 2 if n % 2 == 0 else n 6 | -------------------------------------------------------------------------------- /solutions/2716. Minimize String Length/2716.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minimizedStringLength(String s) { 3 | return new HashSet<>(Arrays.asList(s.split(""))).size(); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/2880. Select Data/2880.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | 4 | def selectData(students: pd.DataFrame) -> pd.DataFrame: 5 | return students.loc[students['student_id'] == 101, ['name', 'age']] 6 | -------------------------------------------------------------------------------- /solutions/3028. Ant on the Boundary/3028.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def returnToBoundaryCount(self, nums: list[int]) -> int: 3 | return sum(prefix == 0 for prefix in itertools.accumulate(nums)) 4 | -------------------------------------------------------------------------------- /solutions/3110. Score of a String/3110.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def scoreOfString(self, s: str) -> int: 3 | return sum(abs(ord(a) - ord(b)) 4 | for a, b in itertools.pairwise(s)) 5 | -------------------------------------------------------------------------------- /solutions/3492. Maximum Containers on a Ship/3492.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxContainers(int n, int w, int maxWeight) { 4 | return min(n * n, maxWeight / w); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/476. Number Complement/476.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int findComplement(int num) { 3 | for (long i = 1; i <= num; i <<= 1) 4 | num ^= i; 5 | return num; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /solutions/796. Rotate String/796.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean rotateString(String s, String goal) { 3 | return s.length() == goal.length() && (s + s).contains(goal); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/1667. Fix Names in a Table/1667.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | user_id, 3 | CONCAT( 4 | UPPER(SUBSTRING(name, 1, 1)), 5 | LOWER(SUBSTRING(name, 2)) 6 | ) AS name 7 | FROM Users 8 | ORDER BY 1; 9 | -------------------------------------------------------------------------------- /solutions/2057. Smallest Index With Equal Value/2057.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def smallestEqual(self, nums: list[int]) -> int: 3 | return next((i for i, num in enumerate(nums) if i % 10 == num), -1) 4 | -------------------------------------------------------------------------------- /solutions/2229. Check if an Array Is Consecutive/2229.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isConsecutive(self, nums: list[int]) -> bool: 3 | return max(nums) - min(nums) + 1 == len(set(nums)) == len(nums) 4 | -------------------------------------------------------------------------------- /solutions/2236. Root Equals Sum of Children/2236.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool checkTree(TreeNode* root) { 4 | return root->val == root->left->val + root->right->val; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/2527. Find Xor-Beauty of Array/2527.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int xorBeauty(vector& nums) { 4 | return accumulate(nums.begin(), nums.end(), 0, bit_xor<>()); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/2651. Calculate Delayed Arrival Time/2651.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findDelayedArrivalTime(self, arrivalTime: int, delayedTime: int) -> int: 3 | return (arrivalTime + delayedTime) % 24 4 | -------------------------------------------------------------------------------- /solutions/2729. Check if The Number is Fascinating/2729.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isFascinating(self, n): 3 | s = str(n) + str(2 * n) + str(3 * n) 4 | return ''.join(sorted(s)) == '123456789' 5 | -------------------------------------------------------------------------------- /solutions/2740. Find the Value of the Partition/2740.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findValueOfPartition(self, nums: list[int]) -> int: 3 | return min(b - a for a, b in itertools.pairwise(sorted(nums))) 4 | -------------------------------------------------------------------------------- /solutions/2833. Furthest Point From Origin/2833.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def furthestDistanceFromOrigin(self, moves: str) -> int: 3 | return abs(moves.count('L') - moves.count('R')) + moves.count('_') 4 | -------------------------------------------------------------------------------- /solutions/2888. Reshape Data: Concatenate/2888.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | 4 | def concatenateTables(df1: pd.DataFrame, df2: pd.DataFrame) -> pd.DataFrame: 5 | return pd.concat([df1, df2], axis=0) 6 | -------------------------------------------------------------------------------- /solutions/290. Word Pattern/290.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def wordPattern(self, pattern: str, str: str) -> bool: 3 | t = str.split() 4 | return [*map(pattern.index, pattern)] == [*map(t.index, t)] 5 | -------------------------------------------------------------------------------- /solutions/2914. Minimum Number of Changes to Make Binary String Beautiful/2914.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minChanges(self, s: str) -> int: 3 | return sum(a != b for a, b in zip(s[::2], s[1::2])) 4 | -------------------------------------------------------------------------------- /solutions/2985. Calculate Compressed Mean/2985.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | ROUND( 3 | SUM(item_count * order_occurrences) / SUM(order_occurrences), 4 | 2 5 | ) AS average_items_per_order 6 | FROM Orders; 7 | -------------------------------------------------------------------------------- /solutions/3222. Find the Winning Player in Coin Game/3222.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String losingPlayer(int x, int y) { 3 | return Math.min(x, y / 4) % 2 == 0 ? "Bob" : "Alice"; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/3300. Minimum Element After Replacement With Digit Sum/3300.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minElement(self, nums: list[int]) -> int: 3 | return min(sum(map(int, str(num))) for num in nums) 4 | -------------------------------------------------------------------------------- /solutions/3456. Find Special Substring of Length K/3456.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def hasSpecialSubstring(self, s: str, k: int) -> bool: 3 | return any(len(list(group)) == k for _, group in groupby(s)) 4 | -------------------------------------------------------------------------------- /solutions/3560. Find Minimum Log Transportation Cost/3560.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public long minCuttingCost(long n, long m, int k) { 3 | return Math.max(0, Math.max(n, m) - k) * k; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/521. Longest Uncommon Subsequence I/521.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findLUSlength(string a, string b) { 4 | return a == b ? -1 : max(a.length(), b.length()); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/551. Student Attendance Record I/551.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean checkRecord(String s) { 3 | return s.indexOf("A") == s.lastIndexOf("A") && !s.contains("LLL"); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/657. Robot Return to Origin/657.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def judgeCircle(self, moves: str) -> bool: 3 | return moves.count('R') == moves.count('L') and moves.count('U') == moves.count('D') 4 | -------------------------------------------------------------------------------- /solutions/1332. Remove Palindromic Subsequences/1332.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int removePalindromeSub(string s) { 4 | return equal(s.begin(), s.end(), s.rbegin()) ? 1 : 2; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/1784. Check if Binary String Has at Most One Segment of Ones/1784.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool checkOnesSegment(string s) { 4 | return s.find("01") == string::npos; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/1979. Find Greatest Common Divisor of Array/1979.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findGCD(vector& nums) { 4 | return __gcd(ranges::min(nums), ranges::max(nums)); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/2206. Divide Array Into Equal Pairs/2206.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def divideArray(self, nums: list[int]) -> bool: 3 | return all(value % 2 == 0 for value in collections.Counter(nums).values()) 4 | -------------------------------------------------------------------------------- /solutions/2469. Convert the Temperature/2469.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector convertTemperature(double celsius) { 4 | return {celsius + 273.15, celsius * 1.8 + 32}; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/2469. Convert the Temperature/2469.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public double[] convertTemperature(double celsius) { 3 | return new double[] {celsius + 273.15, celsius * 1.8 + 32}; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/2480. Form a Chemical Bond/2480.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | A.symbol AS metal, 3 | B.symbol AS nonmetal 4 | FROM Elements AS A, Elements AS B 5 | WHERE 6 | A.type = 'Metal' 7 | AND B.type = 'Nonmetal' 8 | -------------------------------------------------------------------------------- /solutions/2481. Minimum Cuts to Divide a Circle/2481.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int numberOfCuts(int n) { 3 | if (n == 1) 4 | return 0; 5 | return n % 2 == 0 ? n / 2 : n; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /solutions/2668. Find Latest Salaries/2668.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | emp_id, 3 | firstname, 4 | lastname, 5 | MAX(salary) AS salary, 6 | department_id 7 | FROM Salary 8 | GROUP BY 1 9 | ORDER BY 1; 10 | -------------------------------------------------------------------------------- /solutions/2710. Remove Trailing Zeros From a String/2710.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string removeTrailingZeros(string num) { 4 | return regex_replace(num, regex("0+$"), ""); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/2806. Account Balance After Rounded Purchase/2806.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def accountBalanceAfterPurchase(self, purchaseAmount: int) -> int: 3 | return 100 - ((purchaseAmount + 5) // 10) * 10 4 | -------------------------------------------------------------------------------- /solutions/3019. Number of Changing Keys/3019.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countKeyChanges(self, s: str) -> int: 3 | return sum(a.lower() != b.lower() 4 | for a, b in itertools.pairwise(s)) 5 | -------------------------------------------------------------------------------- /solutions/3222. Find the Winning Player in Coin Game/3222.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string losingPlayer(int x, int y) { 4 | return min(x, y / 4) % 2 == 0 ? "Bob" : "Alice"; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/3512. Minimum Operations to Make Array Sum Divisible by K/3512.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minOperations(int[] nums, int k) { 3 | return Arrays.stream(nums).sum() % k; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/3560. Find Minimum Log Transportation Cost/3560.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | long long minCuttingCost(long n, long m, int k) { 4 | return max(0L, max(n, m) - k) * k; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/367. Valid Perfect Square/367.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isPerfectSquare(self, num: int) -> bool: 3 | l = bisect.bisect_left(range(num), num, key=lambda m: m * m) 4 | return l**2 == num 5 | -------------------------------------------------------------------------------- /solutions/476. Number Complement/476.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findComplement(long num) { 4 | for (long i = 1; i <= num; i <<= 1) 5 | num ^= i; 6 | return num; 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /solutions/521. Longest Uncommon Subsequence I/521.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int findLUSlength(String a, String b) { 3 | return a.equals(b) ? -1 : Math.max(a.length(), b.length()); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/704. Binary Search/704.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int search(int[] nums, int target) { 3 | final int i = Arrays.binarySearch(nums, target); 4 | return i < 0 ? -1 : i; 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /solutions/1238. Circular Permutation in Binary Representation/1238.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def circularPermutation(self, n: int, start: int) -> list[int]: 3 | return [start ^ i ^ i >> 1 for i in range(1 << n)] 4 | -------------------------------------------------------------------------------- /solutions/1332. Remove Palindromic Subsequences/1332.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int removePalindromeSub(String s) { 3 | return s.equals(new StringBuilder(s).reverse().toString()) ? 1 : 2; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/1518. Water Bottles/1518-2.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numWaterBottles(int numBottles, int numExchange) { 4 | return numBottles + (numBottles - 1) / (numExchange - 1); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/1587. Bank Account Summary II/1587.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | Users.name, 3 | SUM(amount) AS balance 4 | FROM Users 5 | INNER JOIN Transactions 6 | USING (account) 7 | GROUP BY 1 8 | HAVING balance > 10000; 9 | -------------------------------------------------------------------------------- /solutions/168. Excel Sheet Column Title/168.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String convertToTitle(int n) { 3 | return n == 0 ? "" : convertToTitle((n - 1) / 26) + (char) ('A' + ((n - 1) % 26)); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/1768. Merge Strings Alternately/1768.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def mergeAlternately(self, word1: str, word2: str) -> str: 3 | return ''.join(a + b for a, b in zip_longest(word1, word2, fillvalue='')) 4 | -------------------------------------------------------------------------------- /solutions/1941. Check if All Characters Have Equal Number of Occurrences/1941.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def areOccurrencesEqual(self, s: str) -> bool: 3 | return len(set(collections.Counter(s).values())) == 1 4 | -------------------------------------------------------------------------------- /solutions/2278. Percentage of Letter in String/2278.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int percentageLetter(string s, char letter) { 4 | return 100 * ranges::count(s, letter) / s.length(); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/237. Delete Node in a Linked List/237.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void deleteNode(ListNode* node) { 4 | node->val = node->next->val; 5 | node->next = node->next->next; 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /solutions/2481. Minimum Cuts to Divide a Circle/2481.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int numberOfCuts(int n) { 4 | if (n == 1) 5 | return 0; 6 | return n % 2 == 0 ? n / 2 : n; 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /solutions/2543. Check if Point Is Reachable/2543.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isReachable(unsigned targetX, unsigned targetY) { 4 | return popcount(gcd(targetX, targetY)) == 1; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/2545. Sort the Students by Their Kth Score/2545.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sortTheStudents(self, score: list[list[int]], k: int) -> list[list[int]]: 3 | return sorted(score, key=lambda x: -x[k]) 4 | -------------------------------------------------------------------------------- /solutions/2639. Find the Width of Columns of a Grid/2639.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findColumnWidth(self, grid: list[list[int]]) -> list[int]: 3 | return [max(map(len, map(str, col))) for col in zip(*grid)] 4 | -------------------------------------------------------------------------------- /solutions/2651. Calculate Delayed Arrival Time/2651.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int findDelayedArrivalTime(int arrivalTime, int delayedTime) { 3 | return (arrivalTime + delayedTime) % 24; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/2679. Sum in a Matrix/2679.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def matrixSum(self, nums: list[list[int]]) -> int: 3 | for row in nums: 4 | row.sort() 5 | 6 | return sum(max(col) for col in zip(*nums)) 7 | -------------------------------------------------------------------------------- /solutions/2883. Drop Missing Data/2883.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | 4 | def dropMissingData(students: pd.DataFrame) -> pd.DataFrame: 5 | students.dropna(subset=['name'], inplace=True) 6 | return students 7 | -------------------------------------------------------------------------------- /solutions/2884. Modify Columns/2884.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | 4 | def modifySalaryColumn(employees: pd.DataFrame) -> pd.DataFrame: 5 | employees['salary'] = employees['salary'] * 2 6 | return employees 7 | -------------------------------------------------------------------------------- /solutions/2887. Fill Missing Data/2887.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | 4 | def fillMissingValues(products: pd.DataFrame) -> pd.DataFrame: 5 | products['quantity'].fillna(0, inplace=True) 6 | return products 7 | -------------------------------------------------------------------------------- /solutions/3083. Existence of a Substring in a String and Its Reverse/3083.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isSubstringPresent(self, s: str) -> bool: 3 | return any(s[i:i + 2] in s[::-1] for i in range(len(s) - 1)) 4 | -------------------------------------------------------------------------------- /solutions/3190. Find Minimum Operations to Make All Elements Divisible by Three/3190.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumOperations(self, nums: list[int]) -> int: 3 | return sum(num % 3 != 0 for num in nums) 4 | -------------------------------------------------------------------------------- /solutions/3232. Find if Digit Game Can Be Won/3232.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean canAliceWin(int[] nums) { 3 | return Arrays.stream(nums).map(num -> num < 10 ? num : -num).sum() != 0; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/3498. Reverse Degree of a String/3498.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reverseDegree(self, s: str) -> int: 3 | return sum((26 - (ord(c) - ord('a'))) * (i + 1) 4 | for i, c in enumerate(s)) 5 | -------------------------------------------------------------------------------- /solutions/512. Game Play Analysis II/512.sql: -------------------------------------------------------------------------------- 1 | SELECT DISTINCT 2 | player_id, 3 | FIRST_VALUE(device_id) OVER( 4 | PARTITION by player_id 5 | ORDER BY event_date 6 | ) AS device_id 7 | FROM Activity; 8 | -------------------------------------------------------------------------------- /solutions/574. Winning Candidate/574.sql: -------------------------------------------------------------------------------- 1 | SELECT Candidate.name 2 | FROM Candidate 3 | INNER JOIN Vote 4 | ON (Candidate.id = Vote.candidateId) 5 | GROUP BY Candidate.id 6 | ORDER BY COUNT(*) DESC 7 | LIMIT 1; 8 | -------------------------------------------------------------------------------- /solutions/578. Get Highest Answer Rate Question/578.sql: -------------------------------------------------------------------------------- 1 | SELECT question_id AS survey_log 2 | FROM SurveyLog 3 | GROUP BY 1 4 | ORDER BY 5 | COUNT(answer_id) / COUNT(*) DESC, 6 | question_id ASC 7 | LIMIT 1; 8 | -------------------------------------------------------------------------------- /solutions/660. Remove 9/660.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def newInteger(self, n: int) -> int: 3 | ans = [] 4 | while n: 5 | ans.append(str(n % 9)) 6 | n //= 9 7 | return ''.join(reversed(ans)) 8 | -------------------------------------------------------------------------------- /solutions/771. Jewels and Stones/771.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numJewelsInStones(self, jewels: str, stones: str) -> int: 3 | jewelsSet = set(jewels) 4 | return sum(stone in jewelsSet for stone in stones) 5 | -------------------------------------------------------------------------------- /solutions/796. Rotate String/796.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool rotateString(string s, string goal) { 4 | return s.length() == goal.length() && (s + s).find(goal) != string::npos; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/899. Orderly Queue/899.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def orderlyQueue(self, s: str, k: int) -> str: 3 | return (''.join(sorted(s)) if k > 1 4 | else min(s[i:] + s[:i] for i in range(len(s)))) 5 | -------------------------------------------------------------------------------- /solutions/1009. Complement of Base 10 Integer/1009.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def bitwiseComplement(self, n: int) -> int: 3 | mask = 1 4 | while mask < n: 5 | mask = (mask << 1) + 1 6 | return mask ^ n 7 | -------------------------------------------------------------------------------- /solutions/1791. Find Center of Star Graph/1791.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findCenter(self, edges: list[list[int]]) -> int: 3 | if edges[0][0] in edges[1]: 4 | return edges[0][0] 5 | return edges[0][1] 6 | -------------------------------------------------------------------------------- /solutions/1859. Sorting the Sentence/1859.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sortSentence(self, s: str) -> str: 3 | return ' '.join([word[:-1] 4 | for word in sorted(s.split(), key=lambda x: x[-1])]) 5 | -------------------------------------------------------------------------------- /solutions/1980. Find Unique Binary String/1980-2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findDifferentBinaryString(self, nums: list[str]) -> str: 3 | return ''.join('1' if num[i] == '0' else '0' for i, num in enumerate(nums)) 4 | -------------------------------------------------------------------------------- /solutions/2651. Calculate Delayed Arrival Time/2651.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findDelayedArrivalTime(int arrivalTime, int delayedTime) { 4 | return (arrivalTime + delayedTime) % 24; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/2798. Number of Employees Who Met the Target/2798.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numberOfEmployeesWhoMetTarget(self, hours: list[int], target: int) -> int: 3 | return sum(hour >= target for hour in hours) 4 | -------------------------------------------------------------------------------- /solutions/2806. Account Balance After Rounded Purchase/2806.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int accountBalanceAfterPurchase(int purchaseAmount) { 3 | return 100 - ((purchaseAmount + 5) / 10) * 10; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/2881. Create a New Column/2881.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | 4 | def createBonusColumn(employees: pd.DataFrame) -> pd.DataFrame: 5 | employees['bonus'] = employees['salary'] * 2 6 | return employees 7 | -------------------------------------------------------------------------------- /solutions/3059. Find All Unique Email Domains/3059.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | SUBSTRING_INDEX(email, '@', -1) AS email_domain, 3 | COUNT(*) AS count 4 | FROM Emails 5 | WHERE email LIKE '%.com' 6 | GROUP BY 1 7 | ORDER BY 1; 8 | -------------------------------------------------------------------------------- /solutions/3084. Count Substrings Starting and Ending with Given Character/3084.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countSubstrings(self, s: str, c: str) -> int: 3 | freq = s.count(c) 4 | return freq * (freq + 1) // 2 5 | -------------------------------------------------------------------------------- /solutions/3210. Find the Encrypted String/3210.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string getEncryptedString(string s, int k) { 4 | k %= s.length(); 5 | return s.substr(k) + s.substr(0, k); 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /solutions/3210. Find the Encrypted String/3210.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String getEncryptedString(String s, int k) { 3 | k %= s.length(); 4 | return s.substring(k) + s.substring(0, k); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /solutions/3330. Find the Original Typed String I/3330.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def possibleStringCount(self, word: str) -> int: 3 | return 1 + sum(a == b 4 | for a, b in itertools.pairwise(word)) 5 | -------------------------------------------------------------------------------- /solutions/1075. Project Employees I/1075.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | Project.project_id, 3 | ROUND(AVG(Employee.experience_years), 2) AS average_years 4 | FROM Project 5 | INNER JOIN Employee 6 | USING (employee_id) 7 | GROUP BY 1; 8 | -------------------------------------------------------------------------------- /solutions/171. Excel Sheet Column Number/171.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int titleToNumber(String columnTitle) { 3 | return columnTitle.chars().reduce(0, (subtotal, c) -> subtotal * 26 + c - '@'); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/1812. Determine Color of a Chessboard Square/1812.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def squareIsWhite(self, coordinates: str) -> bool: 3 | letter, digit = coordinates 4 | return ord(letter) % 2 != int(digit) % 2 5 | -------------------------------------------------------------------------------- /solutions/1832. Check if the Sentence Is Pangram/1832.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool checkIfPangram(string sentence) { 4 | return unordered_set(sentence.begin(), sentence.end()).size() == 26; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/1863. Sum of All Subset XOR Totals/1863-2.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int subsetXORSum(int[] nums) { 3 | return Arrays.stream(nums).reduce((a, b) -> a | b).getAsInt() << nums.length - 1; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/1967. Number of Strings That Appear as Substrings in Word/1967.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numOfStrings(self, patterns: list[str], word: str) -> int: 3 | return sum(pattern in word for pattern in patterns) 4 | -------------------------------------------------------------------------------- /solutions/1988. Find Cutoff Score for Each School/1988.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | Schools.school_id, 3 | IFNULL(MIN(Exam.score), -1) AS score 4 | FROM Schools 5 | LEFT JOIN Exam 6 | ON (capacity >= student_count) 7 | GROUP BY 1; 8 | -------------------------------------------------------------------------------- /solutions/2011. Final Value of Variable After Performing Operations/2011.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def finalValueAfterOperations(self, operations: list[str]) -> int: 3 | return sum(op[1] == '+' or -1 for op in operations) 4 | -------------------------------------------------------------------------------- /solutions/2160. Minimum Sum of Four Digit Number After Splitting Digits/2160.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumSum(self, num: int) -> int: 3 | s = sorted(str(num)) 4 | return int(s[0] + s[2]) + int(s[1] + s[3]) 5 | -------------------------------------------------------------------------------- /solutions/2546. Apply Bitwise Operations to Make Strings Equal/2546.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean makeStringsEqual(String s, String target) { 3 | return s.contains("1") == target.contains("1"); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/2579. Count Total Number of Colored Cells/2579.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | long long coloredCells(int n) { 4 | return static_cast(n) * n + static_cast(n - 1) * (n - 1); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/268. Missing Number/268.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def missingNumber(self, nums: list[int]) -> int: 3 | ans = len(nums) 4 | 5 | for i, num in enumerate(nums): 6 | ans ^= i ^ num 7 | 8 | return ans 9 | -------------------------------------------------------------------------------- /solutions/2738. Count Occurrences in Text/2738.sql: -------------------------------------------------------------------------------- 1 | SELECT 'bull' AS word, SUM(content LIKE '% bull %') AS count 2 | FROM Files 3 | UNION ALL 4 | SELECT 'bear' AS word, SUM(content LIKE '% bear %') AS count 5 | FROM Files; 6 | -------------------------------------------------------------------------------- /solutions/2806. Account Balance After Rounded Purchase/2806.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int accountBalanceAfterPurchase(int purchaseAmount) { 4 | return 100 - ((purchaseAmount + 5) / 10) * 10; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/3051. Find Candidates for Data Scientist Position/3051.sql: -------------------------------------------------------------------------------- 1 | SELECT candidate_id 2 | FROM Candidates 3 | WHERE skill IN ('Python', 'Tableau', 'PostgreSQL') 4 | GROUP BY 1 5 | HAVING COUNT(skill) = 3 6 | ORDER BY 1; 7 | -------------------------------------------------------------------------------- /solutions/3131. Find the Integer Added to Array I/3131.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int addedInteger(vector& nums1, vector& nums2) { 4 | return ranges::min(nums2) - ranges::min(nums1); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/412. Fizz Buzz/412.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def fizzBuzz(self, n: int) -> list[str]: 3 | d = {3: 'Fizz', 5: 'Buzz'} 4 | return [''.join([d[k] for k in d if i % k == 0]) or str(i) for i in range(1, n + 1)] 5 | -------------------------------------------------------------------------------- /solutions/704. Binary Search/704.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def search(self, nums: list[int], target: int) -> int: 3 | i = bisect.bisect_left(nums, target) 4 | return -1 if i == len(nums) or nums[i] != target else i 5 | -------------------------------------------------------------------------------- /solutions/869. Reordered Power of 2/869.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reorderedPowerOf2(self, n: int) -> bool: 3 | count = collections.Counter(str(n)) 4 | return any(Counter(str(1 << i)) == count for i in range(30)) 5 | -------------------------------------------------------------------------------- /solutions/1137. N-th Tribonacci Number/1137-2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def tribonacci(self, n: int) -> int: 3 | dp = [0, 1, 1] 4 | 5 | for i in range(3, n + 1): 6 | dp[i % 3] = sum(dp) 7 | 8 | return dp[n % 3] 9 | -------------------------------------------------------------------------------- /solutions/1211. Queries Quality and Percentage/1211.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | query_name, 3 | ROUND(AVG(rating / position), 2) AS quality, 4 | ROUND(AVG(rating < 3) * 100, 2) AS poor_query_percentage 5 | FROM Queries 6 | GROUP BY 1; 7 | -------------------------------------------------------------------------------- /solutions/1271. Hexspeak/1271.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def toHexspeak(self, num: str) -> str: 3 | s = hex(int(num)).upper()[2:].translate(str.maketrans('01', 'OI')) 4 | return 'ERROR' if any(c.isdigit() for c in s) else s 5 | -------------------------------------------------------------------------------- /solutions/1460. Make Two Arrays Equal by Reversing Subarrays/1460.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def canBeEqual(self, target: list[int], arr: list[int]) -> bool: 3 | return collections.Counter(arr) == collections.Counter(target) 4 | -------------------------------------------------------------------------------- /solutions/1484. Group Sold Products By The Date/1484.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | sell_date, 3 | COUNT(DISTINCT product) AS num_sold, 4 | GROUP_CONCAT(DISTINCT product ORDER BY product) AS products 5 | FROM Activities 6 | GROUP BY 1; 7 | -------------------------------------------------------------------------------- /solutions/1491. Average Salary Excluding the Minimum and Maximum Salary/1491.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def average(self, salary: list[int]) -> float: 3 | return (sum(salary) - max(salary) - min(salary)) / (len(salary) - 2) 4 | -------------------------------------------------------------------------------- /solutions/1619. Mean of Array After Removing Some Elements/1619.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def trimMean(self, arr: list[int]) -> float: 3 | arr.sort() 4 | offset = len(arr) // 20 5 | return mean(arr[offset:-offset]) 6 | -------------------------------------------------------------------------------- /solutions/1668. Maximum Repeating Substring/1668.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxRepeating(self, sequence: str, word: str) -> int: 3 | ans = 1 4 | while word * ans in sequence: 5 | ans += 1 6 | return ans - 1 7 | -------------------------------------------------------------------------------- /solutions/1689. Partitioning Into Minimum Number Of Deci-Binary Numbers/1689.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minPartitions(String n) { 3 | return Character.getNumericValue(n.chars().max().getAsInt()); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/1693. Daily Leads and Partners/1693.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | date_id, 3 | make_name, 4 | COUNT(DISTINCT lead_id) AS unique_leads, 5 | COUNT(DISTINCT partner_id) AS unique_partners 6 | FROM DailySales 7 | GROUP BY 1, 2; 8 | -------------------------------------------------------------------------------- /solutions/1837. Sum of Digits in Base K/1837.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sumBase(self, n: int, k: int) -> int: 3 | ans = 0 4 | 5 | while n > 0: 6 | ans += n % k 7 | n //= k 8 | 9 | return ans 10 | -------------------------------------------------------------------------------- /solutions/2000. Reverse Prefix of Word/2000.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string reversePrefix(string word, char ch) { 4 | reverse(word.begin(), word.begin() + word.find(ch) + 1); 5 | return word; 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /solutions/2129. Capitalize the Title/2129.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def capitalizeTitle(self, title: str) -> str: 3 | return ' '.join(s.lower() if len(s) < 3 4 | else s.capitalize() for s in title.split()) 5 | -------------------------------------------------------------------------------- /solutions/2308. Arrange Table by Gender/2308.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | user_id, 3 | gender 4 | FROM Genders 5 | ORDER BY RANK() OVER( 6 | PARTITION by gender 7 | ORDER BY user_id 8 | ), 9 | LENGTH(gender) DESC; 10 | -------------------------------------------------------------------------------- /solutions/2339. All the Matches of the League/2339.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | Home.team_name AS home_team, 3 | Away.team_name AS away_team 4 | FROM Teams AS Home 5 | INNER JOIN Teams AS Away 6 | WHERE Home.team_name != Away.team_name; 7 | -------------------------------------------------------------------------------- /solutions/2529. Maximum Count of Positive Integer and Negative Integer/2529.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maximumCount(self, nums: list[int]) -> int: 3 | return max(sum(num > 0 for num in nums), sum(num < 0 for num in nums)) 4 | -------------------------------------------------------------------------------- /solutions/2550. Count Collisions of Monkeys on a Polygon/2550.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def monkeyMove(self, n: int) -> int: 3 | MOD = 1_000_000_007 4 | res = pow(2, n, MOD) - 2 5 | return res + MOD if res < 0 else res 6 | -------------------------------------------------------------------------------- /solutions/2629. Function Composition/2629.ts: -------------------------------------------------------------------------------- 1 | type F = (x: number) => number; 2 | 3 | function compose(functions: F[]): F { 4 | return function (x) { 5 | return functions.reduceRight((val, f) => f(val), x); 6 | }; 7 | } 8 | -------------------------------------------------------------------------------- /solutions/2690. Infinite Method Object/2690.ts: -------------------------------------------------------------------------------- 1 | function createInfiniteObject(): Record string> { 2 | return new Proxy( 3 | {}, 4 | { 5 | get: (_, prop: string) => () => prop, 6 | } 7 | ); 8 | } 9 | -------------------------------------------------------------------------------- /solutions/2811. Check if it is Possible to Split Array/2811.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def canSplitArray(self, nums: list[int], m: int) -> bool: 3 | return len(nums) < 3 or any(a + b >= m for a, b in itertools.pairwise(nums)) 4 | -------------------------------------------------------------------------------- /solutions/2877. Create a DataFrame from List/2877.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | 4 | def createDataframe(student_data: list[list[int]]) -> pd.DataFrame: 5 | return pd.DataFrame(student_data, columns=['student_id', 'age']) 6 | -------------------------------------------------------------------------------- /solutions/2997. Minimum Number of Operations to Make Array XOR Equal to K/2997.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minOperations(self, nums: list[int], k: int) -> int: 3 | return functools.reduce(operator.xor, nums, k).bit_count() 4 | -------------------------------------------------------------------------------- /solutions/3032. Count Numbers With Unique Digits II/3032.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numberCount(self, a: int, b: int) -> int: 3 | return sum(len(set(str(num))) == len(str(num)) 4 | for num in range(a, b + 1)) 5 | -------------------------------------------------------------------------------- /solutions/3065. Minimum Operations to Exceed Threshold Value I/3065.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minOperations(int[] nums, int k) { 3 | return (int) Arrays.stream(nums).filter(num -> num < k).count(); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/3360. Stone Removal Game/3360.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def canAliceWin(self, n: int) -> bool: 3 | for stones in range(10, -1, -1): 4 | if stones > n: 5 | return stones % 2 == 1 6 | n -= stones 7 | -------------------------------------------------------------------------------- /solutions/3491. Phone Number Prefix/3491.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def phonePrefix(self, numbers: list[str]) -> bool: 3 | return not any(b.startswith(a) 4 | for a, b in itertools.pairwise(sorted(numbers))) 5 | -------------------------------------------------------------------------------- /solutions/570. Managers with at Least 5 Direct Reports/570.sql: -------------------------------------------------------------------------------- 1 | SELECT Manager.name 2 | FROM Employee 3 | INNER JOIN Employee AS Manager 4 | ON (Employee.managerId = Manager.id) 5 | GROUP BY Manager.id 6 | HAVING COUNT(*) >= 5; 7 | -------------------------------------------------------------------------------- /solutions/1308. Running Total for Different Genders/1308.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | gender, 3 | day, 4 | SUM(score_points) OVER( 5 | PARTITION BY gender 6 | ORDER BY day 7 | ) AS total 8 | FROM Scores 9 | ORDER BY 1, 2; 10 | -------------------------------------------------------------------------------- /solutions/1350. Students With Invalid Departments/1350.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | Students.id, 3 | Students.name 4 | FROM Students 5 | LEFT JOIN Departments 6 | ON (Students.department_id = Departments.id) 7 | WHERE Departments.id IS NULL; 8 | -------------------------------------------------------------------------------- /solutions/136. Single Number/136.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int singleNumber(int[] nums) { 3 | int ans = 0; 4 | 5 | for (final int num : nums) 6 | ans ^= num; 7 | 8 | return ans; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /solutions/1374. Generate a String With Characters That Have Odd Counts/1374.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def generateTheString(self, n: int) -> str: 3 | s = 'a' * n 4 | if n % 2 == 0: 5 | s = s[:-1] + 'b' 6 | return s 7 | -------------------------------------------------------------------------------- /solutions/1389. Create Target Array in the Given Order/1389.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def createTargetArray(self, nums, index): 3 | ans = [] 4 | for num, i in zip(nums, index): 5 | ans.insert(i, num) 6 | return ans 7 | -------------------------------------------------------------------------------- /solutions/1543. Fix Product Name Format/1543.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | LOWER(TRIM(product_name)) AS product_name, 3 | DATE_FORMAT(sale_date, '%Y-%m') AS sale_date, 4 | COUNT(*) AS total 5 | FROM Sales 6 | GROUP BY 1, 2 7 | ORDER BY 1, 2; 8 | -------------------------------------------------------------------------------- /solutions/1877. Minimize Maximum Pair Sum in Array/1877.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minPairSum(self, nums: list[int]) -> int: 3 | nums.sort() 4 | return max(nums[i] + nums[len(nums) - 1 - i] for i in range(len(nums) // 2)) 5 | -------------------------------------------------------------------------------- /solutions/190. Reverse Bits/190.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reverseBits(self, n: int) -> int: 3 | ans = 0 4 | 5 | for i in range(32): 6 | if n >> i & 1: 7 | ans |= 1 << 31 - i 8 | 9 | return ans 10 | -------------------------------------------------------------------------------- /solutions/191. Number of 1 Bits/191.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def hammingWeight(self, n: int) -> int: 3 | ans = 0 4 | 5 | for i in range(32): 6 | if (n >> i) & 1: 7 | ans += 1 8 | 9 | return ans 10 | -------------------------------------------------------------------------------- /solutions/2185. Counting Words With a Given Prefix/2185.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int prefixCount(String[] words, String pref) { 3 | return (int) Arrays.stream(words).filter(w -> w.startsWith(pref)).count(); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/2255. Count Prefixes of a Given String/2255.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int countPrefixes(String[] words, String s) { 3 | return (int) Arrays.stream(words).filter(word -> s.startsWith(word)).count(); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/2278. Percentage of Letter in String/2278.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int percentageLetter(String s, char letter) { 3 | return 100 * (int) s.chars().filter(c -> c == letter).count() / s.length(); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/2496. Maximum Value of a String in an Array/2496.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maximumValue(self, strs: list[str]) -> int: 3 | return max(len(s) if any(c.isalpha() for c in s) else int(s) 4 | for s in strs) 5 | -------------------------------------------------------------------------------- /solutions/2778. Sum of Squares of Special Elements/2778.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sumOfSquares(self, nums: list[int]) -> int: 3 | return sum(num**2 for i, num in enumerate(nums) 4 | if len(nums) % (i + 1) == 0) 5 | -------------------------------------------------------------------------------- /solutions/3512. Minimum Operations to Make Array Sum Divisible by K/3512.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minOperations(vector& nums, int k) { 4 | return accumulate(nums.begin(), nums.end(), 0) % k; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/3513. Number of Unique XOR Triplets I/3513.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def uniqueXorTriplets(self, nums: list[int]) -> int: 3 | n = len(nums) 4 | if n < 3: 5 | return n 6 | return 1 << (int(math.log2(n)) + 1) 7 | -------------------------------------------------------------------------------- /solutions/459. Repeated Substring Pattern/459.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean repeatedSubstringPattern(String s) { 3 | final String ss = s + s; 4 | return ss.substring(1, ss.length() - 1).contains(s); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /solutions/619. Biggest Single Number/619.sql: -------------------------------------------------------------------------------- 1 | WITH 2 | UniqueNumbers AS ( 3 | SELECT num 4 | FROM MyNumbers 5 | GROUP BY 1 6 | HAVING COUNT(num) = 1 7 | ) 8 | SELECT MAX(num) AS num 9 | FROM UniqueNumbers; 10 | -------------------------------------------------------------------------------- /solutions/836. Rectangle Overlap/836.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isRectangleOverlap(self, rec1: list[int], rec2: list[int]) -> bool: 3 | return rec1[0] < rec2[2] and rec2[0] < rec1[2] and rec1[1] < rec2[3] and rec2[1] < rec1[3] 4 | -------------------------------------------------------------------------------- /solutions/914. X of a Kind in a Deck of Cards/914.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def hasGroupsSizeX(self, deck: list[int]) -> bool: 3 | count = collections.Counter(deck) 4 | return functools.reduce(math.gcd, count.values()) >= 2 5 | -------------------------------------------------------------------------------- /solutions/1009. Complement of Base 10 Integer/1009.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int bitwiseComplement(int n) { 3 | int mask = 1; 4 | while (mask < n) 5 | mask = (mask << 1) + 1; 6 | return mask ^ n; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /solutions/104. Maximum Depth of Binary Tree/104.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxDepth(self, root: TreeNode | None) -> int: 3 | if not root: 4 | return 0 5 | return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right)) 6 | -------------------------------------------------------------------------------- /solutions/1113. Reported Posts/1113.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | extra AS report_reason, 3 | COUNT(DISTINCT post_id) AS report_count 4 | FROM Actions 5 | WHERE 6 | ACTION = 'report' 7 | AND DATEDIFF('2019-07-05', action_date) = 1 8 | GROUP BY 1; 9 | -------------------------------------------------------------------------------- /solutions/1141. User Activity for the Past 30 Days I/1141.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | activity_date AS day, 3 | COUNT(DISTINCT user_id) AS active_users 4 | FROM Activity 5 | WHERE activity_date BETWEEN '2019-06-28' AND '2019-07-27' 6 | GROUP BY 1; 7 | -------------------------------------------------------------------------------- /solutions/1217. Play with Chips/1217.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minCostToMoveChips(self, position: list[int]) -> int: 3 | count = [0, 0] 4 | for p in position: 5 | count[p % 2] += 1 6 | return min(count[0], count[1]) 7 | -------------------------------------------------------------------------------- /solutions/1486. XOR Operation in an Array/1486.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def xorOperation(self, n: int, start: int) -> int: 3 | return functools.reduce(operator.xor, 4 | [start + 2 * i for i in range(n)]) 5 | -------------------------------------------------------------------------------- /solutions/168. Excel Sheet Column Title/168.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def convertToTitle(self, n: int) -> str: 3 | return (self.convertToTitle((n - 1) // 26) + chr(ord('A') + (n - 1) % 26) 4 | if n 5 | else '') 6 | -------------------------------------------------------------------------------- /solutions/1708. Largest Subarray Length K/1708.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def largestSubarray(self, nums: list[int], k: int) -> list[int]: 3 | mx = max(nums[:len(nums) - k + 1]) 4 | i = nums.index(mx) 5 | return nums[i:i + k] 6 | -------------------------------------------------------------------------------- /solutions/1720. Decode XORed Array/1720.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def decode(self, encoded: list[int], first: int) -> list[int]: 3 | ans = [first] 4 | 5 | for e in encoded: 6 | ans.append(e ^ ans[-1]) 7 | 8 | return ans 9 | -------------------------------------------------------------------------------- /solutions/1874. Minimize Product Sum of Two Arrays/1874.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minProductSum(self, nums1: list[int], nums2: list[int]) -> int: 3 | return sum([a * b for a, b in zip(sorted(nums1), sorted(nums2, reverse=True))]) 4 | -------------------------------------------------------------------------------- /solutions/222. Count Complete Tree Nodes/222.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int countNodes(TreeNode root) { 3 | if (root == null) 4 | return 0; 5 | return 1 + countNodes(root.left) + countNodes(root.right); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /solutions/222. Count Complete Tree Nodes/222.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countNodes(self, root: TreeNode | None) -> int: 3 | if not root: 4 | return 0 5 | return 1 + self.countNodes(root.left) + self.countNodes(root.right) 6 | -------------------------------------------------------------------------------- /solutions/2268. Minimum Number of Keypresses/2268.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumKeypresses(self, s: str) -> int: 3 | return sum(c * (i // 9 + 1) 4 | for i, c in enumerate(sorted(Counter(s).values(), reverse=True))) 5 | -------------------------------------------------------------------------------- /solutions/2275. Largest Combination With Bitwise AND Greater Than Zero/2275.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def largestCombination(self, candidates: list[int]) -> int: 3 | return max(sum(c >> i & 1 for c in candidates) for i in range(24)) 4 | -------------------------------------------------------------------------------- /solutions/2427. Number of Common Factors/2427.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def commonFactors(self, a: int, b: int) -> int: 3 | gcd = math.gcd(a, b) 4 | return sum(a % i == 0 and b % i == 0 5 | for i in range(1, gcd + 1)) 6 | -------------------------------------------------------------------------------- /solutions/2500. Delete Greatest Value in Each Row/2500.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def deleteGreatestValue(self, grid: list[list[int]]) -> int: 3 | for row in grid: 4 | row.sort() 5 | return sum(max(col) for col in zip(*grid)) 6 | -------------------------------------------------------------------------------- /solutions/2587. Rearrange Array to Maximize Prefix Score/2587.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxScore(self, nums: list[int]) -> int: 3 | return sum(num > 0 4 | for num in itertools.accumulate(sorted(nums, reverse=True))) 5 | -------------------------------------------------------------------------------- /solutions/2733. Neither Minimum nor Maximum/2733.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int findNonMinOrMax(int[] nums) { 3 | if (nums.length < 3) 4 | return -1; 5 | Arrays.sort(nums, 0, 3); 6 | return nums[1]; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /solutions/2951. Find the Peaks/2951.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findPeaks(self, mountain: list[int]) -> list[int]: 3 | return [i for i in range(1, len(mountain) - 1) 4 | if mountain[i - 1] < mountain[i] > mountain[i + 1]] 5 | -------------------------------------------------------------------------------- /solutions/3223. Minimum Length of String After Operations/3223.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumLength(self, s: str) -> int: 3 | count = collections.Counter(s) 4 | return sum(2 if freq % 2 == 0 else 1 for freq in count.values()) 5 | -------------------------------------------------------------------------------- /solutions/3226. Number of Bit Changes to Make Two Integers Equal/3226.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minChanges(self, n: int, k: int) -> int: 3 | # n needs to be a superset of k. 4 | return (n ^ k).bit_count() if (n & k) == k else -1 5 | -------------------------------------------------------------------------------- /solutions/717. 1-bit and 2-bit Characters/717.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isOneBitCharacter(self, bits: list[int]) -> bool: 3 | i = 0 4 | while i < len(bits) - 1: 5 | i += bits[i] + 1 6 | 7 | return i == len(bits) - 1 8 | -------------------------------------------------------------------------------- /solutions/104. Maximum Depth of Binary Tree/104.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maxDepth(TreeNode root) { 3 | if (root == null) 4 | return 0; 5 | return 1 + Math.max(maxDepth(root.left), maxDepth(root.right)); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /solutions/1133. Largest Unique Number/1133.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def largestUniqueNumber(self, nums: list[int]) -> int: 3 | return max([num for num, freq in collections.Counter(nums).items() 4 | if freq == 1], default=-1) 5 | -------------------------------------------------------------------------------- /solutions/1407. Top Travellers/1407.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | Users.name, 3 | IFNULL(SUM(Rides.distance), 0) AS travelled_distance 4 | FROM Users 5 | LEFT JOIN Rides 6 | ON (Users.id = Rides.user_id) 7 | GROUP BY Users.id 8 | ORDER BY 2 DESC, 1; 9 | -------------------------------------------------------------------------------- /solutions/1486. XOR Operation in an Array/1486.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int xorOperation(int n, int start) { 3 | int ans = 0; 4 | for (int i = 0; i < n; ++i) 5 | ans ^= start + 2 * i; 6 | return ans; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /solutions/168. Excel Sheet Column Title/168.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string convertToTitle(int n) { 4 | return n == 0 ? "" 5 | : convertToTitle((n - 1) / 26) + (char)('A' + ((n - 1) % 26)); 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /solutions/1748. Sum of Unique Elements/1748.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sumOfUnique(self, nums: list[int]) -> int: 3 | return sum(num 4 | for num, freq in collections.Counter(nums).items() 5 | if freq == 1) 6 | -------------------------------------------------------------------------------- /solutions/181. Employees Earning More Than Their Managers/181.sql: -------------------------------------------------------------------------------- 1 | SELECT Worker.name AS Employee 2 | FROM Employee AS Worker 3 | INNER JOIN Employee AS Manager 4 | ON (Worker.managerId = Manager.id) 5 | WHERE Worker.salary > Manager.salary; 6 | -------------------------------------------------------------------------------- /solutions/1844. Replace All Digits with Characters/1844.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string replaceDigits(string s) { 4 | for (int i = 1; i < s.length(); i += 2) 5 | s[i] += s[i - 1] - '0'; 6 | return s; 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /solutions/1934. Confirmation Rate/1934.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | Signups.user_id, 3 | IFNULL(ROUND(AVG(Confirmations.action = 'confirmed'), 2), 0) AS confirmation_rate 4 | FROM Signups 5 | LEFT JOIN Confirmations 6 | USING (user_id) 7 | GROUP BY 1; 8 | -------------------------------------------------------------------------------- /solutions/2063. Vowels of All Substrings/2063-2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countVowels(self, word: str) -> int: 3 | return sum((i + 1) * (len(word) - i) 4 | for i, c in enumerate(word) 5 | if c in 'aeiou') 6 | -------------------------------------------------------------------------------- /solutions/2164. Sort Even and Odd Indices Independently/2164-2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sortEvenOdd(self, nums: list[int]) -> list[int]: 3 | nums[::2] = sorted(nums[::2]) 4 | nums[1::2] = sorted(nums[1::2])[::-1] 5 | return nums 6 | -------------------------------------------------------------------------------- /solutions/2177. Find Three Consecutive Integers That Sum to a Given Number/2177.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sumOfThree(self, num: int) -> list[int]: 3 | if num % 3: 4 | return [] 5 | x = num // 3 6 | return [x - 1, x, x + 1] 7 | -------------------------------------------------------------------------------- /solutions/2329. Product Sales Analysis V/2329.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | Sales.user_id, 3 | SUM(Sales.quantity * Product.price) AS spending 4 | FROM Sales 5 | INNER JOIN Product 6 | USING (product_id) 7 | GROUP BY user_id 8 | ORDER BY spending DESC; 9 | -------------------------------------------------------------------------------- /solutions/2545. Sort the Students by Their Kth Score/2545.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[][] sortTheStudents(int[][] score, int k) { 3 | Arrays.sort(score, Comparator.comparingInt(a -> - a[k])); 4 | return score; 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /solutions/2652. Sum Multiples/2652.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sumOfMultiples(self, n: int) -> int: 3 | ans = 0 4 | for i in range(1, n + 1): 5 | if i % 3 == 0 or i % 5 == 0 or i % 7 == 0: 6 | ans += i 7 | return ans 8 | -------------------------------------------------------------------------------- /solutions/2723. Add Two Promises/2723.ts: -------------------------------------------------------------------------------- 1 | type P = Promise; 2 | 3 | async function addTwoPromises(promise1: P, promise2: P): P { 4 | const results = await Promise.all([promise1, promise2]); 5 | return results[0] + results[1]; 6 | } 7 | -------------------------------------------------------------------------------- /solutions/2882. Drop Duplicate Rows/2882.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | 4 | def dropDuplicateEmails(customers: pd.DataFrame) -> pd.DataFrame: 5 | customers.drop_duplicates(subset='email', keep='first', inplace=True) 6 | return customers 7 | -------------------------------------------------------------------------------- /solutions/2989. Class Performance/2989.sql: -------------------------------------------------------------------------------- 1 | WITH 2 | TotalScores AS ( 3 | SELECT assignment1 + assignment2 + assignment3 AS score 4 | FROM Scores 5 | ) 6 | SELECT MAX(score) - MIN(score) AS difference_in_score 7 | FROM TotalScores; 8 | -------------------------------------------------------------------------------- /solutions/3028. Ant on the Boundary/3028.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int returnToBoundaryCount(vector& nums) { 4 | partial_sum(nums.begin(), nums.end(), nums.begin()); 5 | return ranges::count(nums, 0); 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /solutions/3065. Minimum Operations to Exceed Threshold Value I/3065.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minOperations(vector& nums, int k) { 4 | return ranges::count_if(nums, [k](int num) { return num < k; }); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/3131. Find the Integer Added to Array I/3131.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int addedInteger(int[] nums1, int[] nums2) { 3 | return Arrays.stream(nums2).min().getAsInt() - Arrays.stream(nums1).min().getAsInt(); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/3220. Odd and Even Transactions/3220.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | transaction_date, 3 | SUM(IF(amount % 2 = 1, amount, 0)) AS odd_sum, 4 | SUM(IF(amount % 2 = 0, amount, 0)) AS even_sum 5 | FROM Transactions 6 | GROUP BY 1 7 | ORDER BY 1; 8 | -------------------------------------------------------------------------------- /solutions/3282. Reach End of Array With Max Score/3282.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | # Similar to 3205. Maximum Array Hopping Score I 3 | def findMaximumScore(self, nums: list[int]) -> int: 4 | return sum(itertools.accumulate(nums[:-1], max)) 5 | -------------------------------------------------------------------------------- /solutions/3289. The Two Sneaky Numbers of Digitville/3289.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def getSneakyNumbers(self, nums: list[int]) -> list[int]: 3 | return [num for num, freq in collections.Counter(nums).items() 4 | if freq == 2] 5 | -------------------------------------------------------------------------------- /solutions/3379. Transformed Array/3379.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def constructTransformedArray(self, nums: list[int]) -> list[int]: 3 | n = len(nums) 4 | return [nums[(i + num % n + n) % n] 5 | for i, num in enumerate(nums)] 6 | -------------------------------------------------------------------------------- /solutions/3467. Transform Array by Parity/3467.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def transformArray(self, nums: list[int]) -> list[int]: 3 | return ([0] * sum(num % 2 == 0 for num in nums) + 4 | [1] * sum(num % 2 == 1 for num in nums)) 5 | -------------------------------------------------------------------------------- /solutions/3516. Find Closest Person/3516.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findClosest(self, x: int, y: int, z: int) -> int: 3 | xz = abs(x - z) 4 | yz = abs(y - z) 5 | if xz == yz: 6 | return 0 7 | return 1 if xz < yz else 2 8 | -------------------------------------------------------------------------------- /solutions/520. Detect Capital/520.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean detectCapitalUse(String word) { 3 | return word.equals(word.toUpperCase()) || 4 | word.substring(1).equals(word.substring(1).toLowerCase()); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /solutions/775. Global and Local Inversions/775-2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isIdealPermutation(self, nums: list[int]) -> bool: 3 | for i, num in enumerate(nums): 4 | if abs(num - i) > 1: 5 | return False 6 | return True 7 | -------------------------------------------------------------------------------- /solutions/1083. Sales Analysis II/1083.sql: -------------------------------------------------------------------------------- 1 | SELECT Sales.buyer_id 2 | FROM Sales 3 | INNER JOIN Product 4 | USING (product_id) 5 | GROUP BY 1 6 | HAVING 7 | SUM(Product.product_name = 'S8') > 0 8 | AND SUM(Product.product_name = 'iPhone') = 0; 9 | -------------------------------------------------------------------------------- /solutions/136. Single Number/136.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int singleNumber(vector& nums) { 4 | int ans = 0; 5 | 6 | for (const int num : nums) 7 | ans ^= num; 8 | 9 | return ans; 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /solutions/1470. Shuffle the Array/1470.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def shuffle(self, nums: list[int], n: int) -> list[int]: 3 | ans = [] 4 | for a, b in zip(nums[:n], nums[n:]): 5 | ans.append(a) 6 | ans.append(b) 7 | return ans 8 | -------------------------------------------------------------------------------- /solutions/1684. Count the Number of Consistent Strings/1684.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countConsistentStrings(self, allowed: str, words: list[str]) -> int: 3 | return sum(all(c in allowed for c in word) 4 | for word in words) 5 | -------------------------------------------------------------------------------- /solutions/1863. Sum of All Subset XOR Totals/1863-2.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int subsetXORSum(vector& nums) { 4 | return accumulate(nums.begin(), nums.end(), 0, bit_or<>()) 5 | << nums.size() - 1; 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /solutions/1940. Longest Common Subsequence Between Sorted Arrays/1940-2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def longestCommonSubsequence(self, arrays: list[list[int]]) -> list[int]: 3 | return sorted(functools.reduce(lambda a, b: set(a) & set(b), arrays)) 4 | -------------------------------------------------------------------------------- /solutions/197. Rising Temperature/197.sql: -------------------------------------------------------------------------------- 1 | SELECT Today.id 2 | FROM Weather AS Today 3 | INNER JOIN Weather AS Yesterday 4 | ON (DATE_SUB(Today.recordDate, INTERVAL 1 DAY) = Yesterday.recordDate) 5 | WHERE Today.temperature > Yesterday.temperature; 6 | -------------------------------------------------------------------------------- /solutions/2148. Count Elements With Strictly Smaller and Greater Elements/2148.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countElements(self, nums: list[int]) -> int: 3 | mn = min(nums) 4 | mx = max(nums) 5 | return sum(mn < num < mx for num in nums) 6 | -------------------------------------------------------------------------------- /solutions/2446. Determine if Two Events Have Conflict/2446.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool haveConflict(vector& event1, vector& event2) { 4 | return event1[0] <= event2[1] && event2[0] <= event1[1]; 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/275. H-Index II/275.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def hIndex(self, citations: list[int]) -> int: 3 | n = len(citations) 4 | return n - bisect.bisect_left(range(n), n, 5 | key=lambda m: citations[m] + m) 6 | -------------------------------------------------------------------------------- /solutions/2828. Check if a String Is an Acronym of Words/2828.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isAcronym(self, words: list[str], s: str) -> bool: 3 | return (len(words) == len(s) and 4 | all(word[0] == c for word, c in zip(words, s))) 5 | -------------------------------------------------------------------------------- /solutions/2859. Sum of Values at Indices With K Set Bits/2859.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sumIndicesWithKSetBits(self, nums: list[int], k: int) -> int: 3 | return sum(num for i, num in enumerate(nums) 4 | if i.bit_count() == k) 5 | -------------------------------------------------------------------------------- /solutions/3190. Find Minimum Operations to Make All Elements Divisible by Three/3190.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minimumOperations(int[] nums) { 3 | return (int) Arrays.stream(nums).filter(num -> num % 3 != 0).count(); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/3285. Find Indices of Stable Mountains/3285.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def stableMountains(self, height: list[int], threshold: int) -> list[int]: 3 | return [i for i in range(1, len(height)) 4 | if height[i - 1] > threshold] 5 | -------------------------------------------------------------------------------- /solutions/3295. Report Spam Message/3295.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reportSpam(self, message: list[str], bannedWords: list[str]) -> bool: 3 | bannedWordsSet = set(bannedWords) 4 | return sum(word in bannedWordsSet for word in message) > 1 5 | -------------------------------------------------------------------------------- /solutions/3392. Count Subarrays of Length Three With a Condition/3392.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countSubarrays(self, nums: list[int]) -> int: 3 | return sum(b == (a + c) * 2 4 | for a, b, c in zip(nums, nums[1:], nums[2:])) 5 | -------------------------------------------------------------------------------- /solutions/3407. Substring Matching Pattern/3407.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def hasMatch(self, s: str, p: str) -> bool: 3 | prefix, suffix = p.split('*') 4 | i = s.find(prefix) 5 | return i != -1 and s.find(suffix, i + len(prefix)) != -1 6 | -------------------------------------------------------------------------------- /solutions/344. Reverse String/344.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void reverseString(vector& s) { 4 | int l = 0; 5 | int r = s.size() - 1; 6 | 7 | while (l < r) 8 | swap(s[l++], s[r--]); 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /solutions/344. Reverse String/344.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def reverseString(self, s: list[str]) -> None: 3 | l = 0 4 | r = len(s) - 1 5 | 6 | while l < r: 7 | s[l], s[r] = s[r], s[l] 8 | l += 1 9 | r -= 1 10 | -------------------------------------------------------------------------------- /solutions/3487. Maximum Unique Subarray Sum After Deletion/3487.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxSum(self, nums: list[int]) -> int: 3 | mx = max(nums) 4 | if mx <= 0: 5 | return mx 6 | return sum(max(0, num) for num in set(nums)) 7 | -------------------------------------------------------------------------------- /solutions/459. Repeated Substring Pattern/459.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool repeatedSubstringPattern(string s) { 4 | const string ss = s + s; 5 | return ss.substr(1, ss.length() - 2).find(s) != string::npos; 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /solutions/580. Count Student Number in Departments/580.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | Department.dept_name, 3 | COUNT(Student.student_id) AS student_number 4 | FROM Department 5 | LEFT JOIN Student 6 | USING (dept_id) 7 | GROUP BY 1 8 | ORDER BY 2 DESC, 1; 9 | -------------------------------------------------------------------------------- /solutions/612. Shortest Distance in a Plane/612.sql: -------------------------------------------------------------------------------- 1 | SELECT ROUND( 2 | MIN(SQRT(POW(P1.x - P2.x, 2) + POW(P1.y - P2.y, 2))), 3 | 2 4 | ) AS shortest 5 | FROM Point2D AS P1 6 | LEFT JOIN Point2D AS P2 7 | ON (P1.x, P1.y) != (P2.x, P2.y); 8 | -------------------------------------------------------------------------------- /solutions/628. Maximum Product of Three Numbers/628.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maximumProduct(self, nums: list[int]) -> int: 3 | nums.sort() 4 | return max(nums[-1] * nums[0] * nums[1], 5 | nums[-1] * nums[-2] * nums[-3]) 6 | -------------------------------------------------------------------------------- /solutions/728. Self Dividing Numbers/728.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def selfDividingNumbers(self, left: int, right: int) -> list[int]: 3 | return [num for num in range(left, right + 1) if all(n != 0 and num % n == 0 for n in map(int, str(num)))] 4 | -------------------------------------------------------------------------------- /solutions/810. Chalkboard XOR Game/810.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean xorGame(int[] nums) { 3 | final int xors = Arrays.stream(nums).reduce((a, b) -> a ^ b).getAsInt(); 4 | return xors == 0 || nums.length % 2 == 0; 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /solutions/1002. Find Common Characters/1002.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def commonChars(self, words: list[str]) -> list[str]: 3 | return functools.reduce(lambda a, b: a & b, 4 | map(collections.Counter, words)).elements() 5 | -------------------------------------------------------------------------------- /solutions/1009. Complement of Base 10 Integer/1009.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int bitwiseComplement(int n) { 4 | int mask = 1; 5 | while (mask < n) 6 | mask = (mask << 1) + 1; 7 | return mask ^ n; 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /solutions/104. Maximum Depth of Binary Tree/104.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxDepth(TreeNode* root) { 4 | if (root == nullptr) 5 | return 0; 6 | return 1 + max(maxDepth(root->left), maxDepth(root->right)); 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /solutions/1699. Number of Calls Between Two Persons/1699.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | LEAST(from_id, to_id) AS person1, 3 | GREATEST(from_id, to_id) AS person2, 4 | COUNT(*) AS call_count, 5 | SUM(duration) AS total_duration 6 | FROM Calls 7 | GROUP BY 1, 2; 8 | -------------------------------------------------------------------------------- /solutions/171. Excel Sheet Column Number/171.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def titleToNumber(self, columnTitle: str) -> int: 3 | return functools.reduce(lambda subtotal, c: 4 | subtotal * 26 + ord(c) - ord('@'), columnTitle, 0) 5 | -------------------------------------------------------------------------------- /solutions/1780. Check if Number is a Sum of Powers of Three/1780.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def checkPowersOfThree(self, n: int) -> bool: 3 | while n > 1: 4 | n, r = divmod(n, 3) 5 | if r == 2: 6 | return False 7 | return True 8 | -------------------------------------------------------------------------------- /solutions/1844. Replace All Digits with Characters/1844.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def replaceDigits(self, s: str) -> str: 3 | return ''.join( 4 | c if i % 2 == 0 else chr(ord(s[i - 1]) + int(c)) 5 | for i, c in enumerate(s) 6 | ) 7 | -------------------------------------------------------------------------------- /solutions/1903. Largest Odd Number in String/1903.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def largestOddNumber(self, num: str) -> str: 3 | for i, n in reversed(list(enumerate(num))): 4 | if int(n) % 2 == 1: 5 | return num[:i + 1] 6 | return '' 7 | -------------------------------------------------------------------------------- /solutions/2041. Accepted Candidates From the Interviews/2041.sql: -------------------------------------------------------------------------------- 1 | SELECT Candidates.candidate_id 2 | FROM Candidates 3 | INNER JOIN Rounds 4 | USING (interview_id) 5 | WHERE Candidates.years_of_exp >= 2 6 | GROUP BY 1 7 | HAVING SUM(Rounds.score) > 15; 8 | -------------------------------------------------------------------------------- /solutions/2057. Smallest Index With Equal Value/2057.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int smallestEqual(int[] nums) { 3 | for (int i = 0; i < nums.length; ++i) 4 | if (nums[i] == i % 10) 5 | return i; 6 | return -1; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /solutions/2066. Account Balance/2066.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | account_id, 3 | day, 4 | SUM(IF(type = 'Deposit', amount, -amount)) OVER( 5 | PARTITION BY account_id 6 | ORDER BY day 7 | ) AS balance 8 | FROM Transactions 9 | ORDER BY 1, 2; 10 | -------------------------------------------------------------------------------- /solutions/2128. Remove All Ones With Row and Column Flips/2128.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeOnes(self, grid: list[list[int]]) -> bool: 3 | revRow = [a ^ 1 for a in grid[0]] 4 | return all(row == grid[0] or row == revRow for row in grid) 5 | -------------------------------------------------------------------------------- /solutions/222. Count Complete Tree Nodes/222.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int countNodes(TreeNode* root) { 4 | if (root == nullptr) 5 | return 0; 6 | return 1 + countNodes(root->left) + countNodes(root->right); 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /solutions/2244. Minimum Rounds to Complete All Tasks/2244.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumRounds(self, tasks: list[int]) -> int: 3 | freqs = collections.Counter(tasks).values() 4 | return -1 if 1 in freqs else sum((f + 2) // 3 for f in freqs) 5 | -------------------------------------------------------------------------------- /solutions/2506. Count Pairs Of Similar Strings/2506-2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def similarPairs(self, words: list[str]) -> int: 3 | return sum(set(words[i]) == set(words[j]) 4 | for i, j in itertools.combinations(range(len(words)), 2)) 5 | -------------------------------------------------------------------------------- /solutions/2568. Minimum Impossible OR/2568.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minImpossibleOR(self, nums: list[int]) -> int: 3 | ans = 1 4 | numsSet = set(nums) 5 | 6 | while ans in numsSet: 7 | ans <<= 1 8 | 9 | return ans 10 | -------------------------------------------------------------------------------- /solutions/2632. Curry/2632.ts: -------------------------------------------------------------------------------- 1 | function curry(fn: Function): Function { 2 | return function curried(...args: any[]): any { 3 | return args.length >= fn.length 4 | ? fn.apply(this, args) 5 | : curried.bind(this, ...args); 6 | }; 7 | } 8 | -------------------------------------------------------------------------------- /solutions/2686. Immediate Food Delivery III/2686.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | order_date, 3 | ROUND( 4 | AVG(order_date = customer_pref_delivery_date) * 100, 5 | 2 6 | ) AS immediate_percentage 7 | FROM Delivery 8 | GROUP BY 1 9 | ORDER BY 1; 10 | -------------------------------------------------------------------------------- /solutions/2784. Check if Array is Good/2784.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isGood(self, nums: list[int]) -> bool: 3 | n = len(nums) - 1 4 | count = collections.Counter(nums) 5 | return all(count[i] == 1 for i in range(1, n)) and count[n] == 2 6 | -------------------------------------------------------------------------------- /solutions/2798. Number of Employees Who Met the Target/2798.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int numberOfEmployeesWhoMetTarget(int[] hours, int target) { 3 | return (int) Arrays.stream(hours).filter(hour -> hour >= target).count(); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/2837. Total Traveled Distance/2837.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | Users.user_id, 3 | Users.name, 4 | SUM(IFNULL(Rides.distance, 0)) AS 'traveled distance' 5 | FROM Users 6 | LEFT JOIN Rides 7 | USING (user_id) 8 | GROUP BY 1 9 | ORDER BY 1; 10 | -------------------------------------------------------------------------------- /solutions/3000. Maximum Area of Longest Diagonal Rectangle/3000.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def areaOfMaxDiagonal(self, dimensions: list[list[int]]) -> int: 3 | a, b = max(dimensions, key=lambda x: (x[0]**2 + x[1]**2, x[0] * x[1])) 4 | return a * b 5 | -------------------------------------------------------------------------------- /solutions/3205. Maximum Array Hopping Score I/3205-2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxScore(self, nums: list[int]) -> int: 3 | # The optimal jump is the maximum number in the remaining suffix. 4 | return sum(itertools.accumulate(nums[:0:-1], max)) 5 | -------------------------------------------------------------------------------- /solutions/3226. Number of Bit Changes to Make Two Integers Equal/3226.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minChanges(int n, int k) { 3 | // n needs to be a superset of k. 4 | return (n & k) == k ? Integer.bitCount(n ^ k) : -1; 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /solutions/372. Super Pow/372.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def superPow(self, a: int, b: list[int]) -> int: 3 | MOD = 1337 4 | ans = 1 5 | 6 | for i in b: 7 | ans = pow(ans, 10, MOD) * pow(a, i, MOD) 8 | 9 | return ans % MOD 10 | -------------------------------------------------------------------------------- /solutions/389. Find the Difference/389-2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findTheDifference(self, s: str, t: str) -> str: 3 | count = collections.Counter(s) 4 | 5 | for c in t: 6 | if count[c] == 0: 7 | return c 8 | count[c] -= 1 9 | -------------------------------------------------------------------------------- /solutions/607. Sales Person/607.sql: -------------------------------------------------------------------------------- 1 | SELECT SalesPerson.name 2 | FROM Orders 3 | INNER JOIN Company 4 | ON (Orders.com_id = Company.com_id AND Company.name = 'RED') 5 | RIGHT JOIN SalesPerson 6 | USING (sales_id) 7 | WHERE Orders.sales_id IS NULL; 8 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 80, 3 | "proseWrap": "always", 4 | "singleQuote": true, 5 | "overrides": [ 6 | { 7 | "files": "*.md", 8 | "options": { 9 | "parser": "markdown" 10 | } 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /solutions/1337. The K Weakest Rows in a Matrix/1337.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def kWeakestRows(self, mat: list[list[int]], k: int) -> list[int]: 3 | rowSums = [(sum(row), i) for i, row in enumerate(mat)] 4 | return [i for _, i in sorted(rowSums)[:k]] 5 | -------------------------------------------------------------------------------- /solutions/1486. XOR Operation in an Array/1486.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int xorOperation(int n, int start) { 4 | int ans = 0; 5 | for (int i = 0; i < n; ++i) 6 | ans ^= start + 2 * i; 7 | return ans; 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /solutions/1607. Sellers With No Sales/1607.sql: -------------------------------------------------------------------------------- 1 | SELECT Seller.seller_name 2 | FROM Seller 3 | LEFT JOIN Orders 4 | ON ( 5 | Seller.seller_id = Orders.seller_id 6 | AND YEAR(Orders.sale_date) = 2020) 7 | WHERE Orders.order_id IS NULL 8 | ORDER BY 1; 9 | -------------------------------------------------------------------------------- /solutions/1791. Find Center of Star Graph/1791.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int findCenter(int[][] edges) { 3 | return edges[0][0] == edges[1][0] || edges[0][0] == edges[1][1] // 4 | ? edges[0][0] 5 | : edges[0][1]; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /solutions/1897. Redistribute Characters to Make All Strings Equal/1897.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def makeEqual(self, words: list[str]) -> bool: 3 | return all(c % len(words) == 0 4 | for c in collections.Counter(''.join(words)).values()) 5 | -------------------------------------------------------------------------------- /solutions/2154. Keep Multiplying Found Values by Two/2155.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findFinalValue(self, nums: list[int], original: int) -> int: 3 | numsSet = set(nums) 4 | while original in numsSet: 5 | original *= 2 6 | return original 7 | -------------------------------------------------------------------------------- /solutions/2446. Determine if Two Events Have Conflict/2446.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean haveConflict(String[] event1, String[] event2) { 3 | return event1[0].compareTo(event2[1]) <= 0 && event2[0].compareTo(event1[1]) <= 0; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/2546. Apply Bitwise Operations to Make Strings Equal/2546.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool makeStringsEqual(string s, string target) { 4 | return (s.find('1') != string::npos) == (target.find('1') != string::npos); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/2974. Minimum Number Game/2974.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numberGame(self, nums: list[int]) -> list[int]: 3 | nums.sort() 4 | return [nums[i + 1] if i % 2 == 0 5 | else nums[i - 1] 6 | for i in range(len(nums))] 7 | -------------------------------------------------------------------------------- /solutions/3150. Invalid Tweets II/3150.sql: -------------------------------------------------------------------------------- 1 | SELECT tweet_id 2 | FROM Tweets 3 | WHERE 4 | LENGTH(content) > 140 5 | OR LENGTH(content) - LENGTH(REPLACE(content, '@', '')) > 3 6 | OR LENGTH(content) - LENGTH(REPLACE(content, '#', '')) > 3 7 | ORDER BY 1; 8 | -------------------------------------------------------------------------------- /solutions/3172. Second Day Verification/3172.sql: -------------------------------------------------------------------------------- 1 | SELECT Emails.user_id 2 | FROM Emails 3 | INNER JOIN Texts 4 | USING (email_id) 5 | WHERE 6 | Texts.signup_action = 'Verified' 7 | AND DATEDIFF(Texts.action_date, Emails.signup_date) = 1 8 | ORDER BY 1; 9 | -------------------------------------------------------------------------------- /solutions/3190. Find Minimum Operations to Make All Elements Divisible by Three/3190.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minimumOperations(vector& nums) { 4 | return ranges::count_if(nums, [](int num) { return num % 3 != 0; }); 5 | } 6 | }; 7 | -------------------------------------------------------------------------------- /solutions/3226. Number of Bit Changes to Make Two Integers Equal/3226.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minChanges(unsigned n, unsigned k) { 4 | // n needs to be a superset of k. 5 | return (n & k) == k ? popcount(n ^ k) : -1; 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /solutions/3415. Find Products with Three Consecutive Digits/3415.sql: -------------------------------------------------------------------------------- 1 | SELECT product_id, name 2 | FROM Products 3 | WHERE 4 | name REGEXP '[^0-9][0-9]{3}[^0-9]' 5 | OR name REGEXP '^[0-9]{3}[^0-9]' 6 | OR name REGEXP '[^0-9][0-9]{3}$' 7 | ORDER BY 1; 8 | -------------------------------------------------------------------------------- /solutions/3423. Maximum Difference Between Adjacent Elements in a Circular Array/3423.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxAdjacentDistance(self, nums: list[int]) -> int: 3 | return max(abs(nums[i] - nums[i - 1]) 4 | for i in range(len(nums))) 5 | -------------------------------------------------------------------------------- /solutions/3465. Find Products with Valid Serial Numbers/3465.sql: -------------------------------------------------------------------------------- 1 | SELECT product_id, product_name, description 2 | FROM Products 3 | WHERE 4 | description REGEXP 'SN[0-9]{4}-[0-9]{4}$' 5 | OR description REGEXP 'SN[0-9]{4}-[0-9]{4}[^0-9]+' 6 | ORDER BY 1; 7 | -------------------------------------------------------------------------------- /solutions/651. 4 Keys Keyboard/651.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maxA(int n) { 3 | int ans = n; 4 | 5 | for (int i = 1; i <= n - 3; ++i) 6 | ans = Math.max(ans, maxA(i) * (n - 1 - i)); 7 | 8 | return ans; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /solutions/660. Remove 9/660.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int newInteger(int n) { 4 | string ans; 5 | while (n > 0) { 6 | ans = to_string(n % 9) + ans; 7 | n /= 9; 8 | } 9 | return stoi(ans); 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /solutions/810. Chalkboard XOR Game/810.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool xorGame(vector& nums) { 4 | const int xors = accumulate(nums.begin(), nums.end(), 0, bit_xor()); 5 | return xors == 0 || nums.size() % 2 == 0; 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /solutions/893. Groups of Special-Equivalent Strings/893.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numSpecialEquivGroups(self, words: list[str]) -> int: 3 | return len({''.join(sorted(word[::2])) + ''.join(sorted(word[1::2])) 4 | for word in words}) 5 | -------------------------------------------------------------------------------- /solutions/1071. Greatest Common Divisor of Strings/1071-2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def gcdOfStrings(self, str1: str, str2: str) -> str: 3 | if str1 + str2 != str2 + str1: 4 | return '' 5 | g = math.gcd(len(str1), len(str2)) 6 | return str1[:g] 7 | -------------------------------------------------------------------------------- /solutions/1426. Counting Elements/1426.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countElements(self, arr: list[int]) -> int: 3 | count = collections.Counter(arr) 4 | return sum(freq 5 | for a, freq in count.items() 6 | if count[a + 1] > 0) 7 | -------------------------------------------------------------------------------- /solutions/1565. Unique Orders and Customers Per Month/1565.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | DATE_FORMAT(order_date, '%Y-%m') AS month, 3 | COUNT(order_id) AS order_count, 4 | COUNT(DISTINCT customer_id) AS customer_count 5 | FROM Orders 6 | WHERE invoice > 20 7 | GROUP BY 1; 8 | -------------------------------------------------------------------------------- /solutions/1668. Maximum Repeating Substring/1668.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maxRepeating(String sequence, String word) { 3 | int ans = 1; 4 | while (sequence.contains(word.repeat(ans))) 5 | ++ans; 6 | return ans - 1; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /solutions/1679. Max Number of K-Sum Pairs/1679.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxOperations(self, nums: list[int], k: int) -> int: 3 | count = collections.Counter(nums) 4 | return sum(min(count[num], count[k - num]) 5 | for num in count) // 2 6 | -------------------------------------------------------------------------------- /solutions/1832. Check if the Sentence Is Pangram/1832-2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def checkIfPangram(self, sentence: str) -> bool: 3 | seen = 0 4 | 5 | for c in sentence: 6 | seen |= 1 << ord(c) - ord('a') 7 | 8 | return seen == (1 << 26) - 1 9 | -------------------------------------------------------------------------------- /solutions/1835. Find XOR Sum of All Pairs Bitwise AND/1835.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def getXORSum(self, arr1: list[int], arr2: list[int]) -> int: 3 | return functools.reduce( 4 | operator.xor, arr1) & functools.reduce( 5 | operator.xor, arr2) 6 | -------------------------------------------------------------------------------- /solutions/1837. Sum of Digits in Base K/1837.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int sumBase(int n, int k) { 3 | int ans = 0; 4 | 5 | while (n > 0) { 6 | ans += n % k; 7 | n /= k; 8 | } 9 | 10 | return ans; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /solutions/214. Shortest Palindrome/214.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def shortestPalindrome(self, s: str) -> str: 3 | t = s[::-1] 4 | 5 | for i in range(len(t)): 6 | if s.startswith(t[i:]): 7 | return t[:i] + s 8 | 9 | return t + s 10 | -------------------------------------------------------------------------------- /solutions/2374. Node With Highest Edge Score/2374.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def edgeScore(self, edges: list[int]) -> int: 3 | scores = [0] * len(edges) 4 | for i, edge in enumerate(edges): 5 | scores[edge] += i 6 | return scores.index(max(scores)) 7 | -------------------------------------------------------------------------------- /solutions/2377. Sort the Olympic Table/2377.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | country, 3 | gold_medals, 4 | silver_medals, 5 | bronze_medals 6 | FROM Olympic 7 | ORDER BY 8 | gold_medals DESC, 9 | silver_medals DESC, 10 | bronze_medals DESC, 11 | country; 12 | -------------------------------------------------------------------------------- /solutions/263. Ugly Number/263.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isUgly(self, n: int) -> bool: 3 | if n == 0: 4 | return False 5 | 6 | for prime in 2, 3, 5: 7 | while n % prime == 0: 8 | n //= prime 9 | 10 | return n == 1 11 | -------------------------------------------------------------------------------- /solutions/268. Missing Number/268.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int missingNumber(int[] nums) { 3 | int ans = nums.length; 4 | 5 | for (int i = 0; i < nums.length; ++i) 6 | ans ^= i ^ nums[i]; 7 | 8 | return ans; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /solutions/27. Remove Element/27.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeElement(self, nums: list[int], val: int) -> int: 3 | i = 0 4 | 5 | for num in nums: 6 | if num != val: 7 | nums[i] = num 8 | i += 1 9 | 10 | return i 11 | -------------------------------------------------------------------------------- /solutions/2796. Repeat String/2796.ts: -------------------------------------------------------------------------------- 1 | declare global { 2 | interface String { 3 | replicate(times: number): string; 4 | } 5 | } 6 | 7 | String.prototype.replicate = function (times): string { 8 | return Array(times).fill(this).join(''); 9 | }; 10 | -------------------------------------------------------------------------------- /solutions/2803. Factorial Generator/2803.ts: -------------------------------------------------------------------------------- 1 | function* factorial(n: number): Generator { 2 | if (n === 0) { 3 | yield 1; 4 | } 5 | let fact = 1; 6 | for (let i = 1; i <= n; ++i) { 7 | fact *= i; 8 | yield fact; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /solutions/2891. Method Chaining/2891.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | 4 | def findHeavyAnimals(animals: pd.DataFrame) -> pd.DataFrame: 5 | return animals[animals['weight'] > 100].sort_values( 6 | by='weight', 7 | ascending=False 8 | )[['name']] 9 | -------------------------------------------------------------------------------- /solutions/2979. Most Expensive Item That Can Not Be Bought/2979.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def mostExpensiveItem(self, primeOne: int, primeTwo: int) -> int: 3 | # https://en.wikipedia.org/wiki/Coin_problem 4 | return primeOne * primeTwo - primeOne - primeTwo 5 | -------------------------------------------------------------------------------- /solutions/3151. Special Array I/3151.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isArraySpecial(int[] nums) { 3 | for (int i = 1; i < nums.length; ++i) 4 | if (nums[i] % 2 == nums[i - 1] % 2) 5 | return false; 6 | return true; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /solutions/462. Minimum Moves to Equal Array Elements II/462.py: -------------------------------------------------------------------------------- 1 | import statistics 2 | 3 | 4 | class Solution: 5 | def minMoves2(self, nums: list[int]) -> int: 6 | median = int(statistics.median(nums)) 7 | return sum(abs(num - median) for num in nums) 8 | -------------------------------------------------------------------------------- /solutions/48. Rotate Image/48.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def rotate(self, matrix: list[list[int]]) -> None: 3 | matrix.reverse() 4 | for i, j in itertools.combinations(range(len(matrix)), 2): 5 | matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j] 6 | -------------------------------------------------------------------------------- /solutions/62. Unique Paths/62-2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def uniquePaths(self, m: int, n: int) -> int: 3 | dp = [1] * n 4 | 5 | for _ in range(1, m): 6 | for j in range(1, n): 7 | dp[j] += dp[j - 1] 8 | 9 | return dp[n - 1] 10 | -------------------------------------------------------------------------------- /solutions/651. 4 Keys Keyboard/651.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxA(int n) { 4 | int ans = n; 5 | 6 | for (int i = 1; i <= n - 3; ++i) 7 | ans = max(ans, maxA(i) * (n - 1 - i)); 8 | 9 | return ans; 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /solutions/89. Gray Code/89.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def grayCode(self, n: int) -> list[int]: 3 | ans = [0] 4 | 5 | for i in range(n): 6 | for j in reversed(range(len(ans))): 7 | ans.append(ans[j] | 1 << i) 8 | 9 | return ans 10 | -------------------------------------------------------------------------------- /solutions/908. Smallest Range I/908.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int smallestRangeI(vector& nums, int k) { 4 | const int mx = ranges::max(nums); 5 | const int mn = ranges::min(nums); 6 | return max(0, mx - mn - 2 * k); 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /solutions/1017. Convert to Base -2/1017.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def baseNeg2(self, n: int) -> str: 3 | ans = [] 4 | 5 | while n != 0: 6 | ans.append(str(n % 2)) 7 | n = -(n >> 1) 8 | 9 | return ''.join(reversed(ans)) if ans else '0' 10 | -------------------------------------------------------------------------------- /solutions/1217. Play with Chips/1217.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minCostToMoveChips(int[] position) { 3 | int[] count = new int[2]; 4 | for (final int p : position) 5 | ++count[p % 2]; 6 | return Math.min(count[0], count[1]); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /solutions/1313. Decompress Run-Length Encoded List/1313.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def decompressRLElist(self, nums: list[int]) -> list[int]: 3 | ans = [] 4 | 5 | for i in range(0, len(nums), 2): 6 | ans += [nums[i + 1]] * nums[i] 7 | 8 | return ans 9 | -------------------------------------------------------------------------------- /solutions/137. Single Number II/137.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def singleNumber(self, nums: list[int]) -> int: 3 | ones = 0 4 | twos = 0 5 | 6 | for num in nums: 7 | ones ^= num & ~twos 8 | twos ^= num & ~ones 9 | 10 | return ones 11 | -------------------------------------------------------------------------------- /solutions/1374. Generate a String With Characters That Have Odd Counts/1374.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string generateTheString(int n) { 4 | string s(n, 'a'); 5 | if (n % 2 == 0) 6 | s.back() = 'b'; 7 | return s; 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /solutions/1725. Number Of Rectangles That Can Form The Largest Square/1725.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countGoodRectangles(self, rectangles: list[list[int]]) -> int: 3 | minSides = [min(x, y) for x, y in rectangles] 4 | return minSides.count(max(minSides)) 5 | -------------------------------------------------------------------------------- /solutions/176. Second Highest Salary/176.sql: -------------------------------------------------------------------------------- 1 | WITH 2 | RankedEmployees AS ( 3 | SELECT *, DENSE_RANK() OVER(ORDER BY salary DESC) AS `rank` 4 | FROM Employee 5 | ) 6 | SELECT MAX(salary) AS SecondHighestSalary 7 | FROM RankedEmployees 8 | WHERE `rank` = 2; 9 | -------------------------------------------------------------------------------- /solutions/1809. Ad-Free Sessions/1809.sql: -------------------------------------------------------------------------------- 1 | SELECT Playback.session_id 2 | FROM Playback 3 | LEFT JOIN Ads 4 | ON ( 5 | Playback.customer_id = Ads.customer_id 6 | AND Ads.timestamp BETWEEN Playback.start_time AND Playback.end_time) 7 | WHERE Ads.ad_id IS NULL; 8 | -------------------------------------------------------------------------------- /solutions/1837. Sum of Digits in Base K/1837.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int sumBase(int n, int k) { 4 | int ans = 0; 5 | 6 | while (n > 0) { 7 | ans += n % k; 8 | n /= k; 9 | } 10 | 11 | return ans; 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /solutions/1967. Number of Strings That Appear as Substrings in Word/1967.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int numOfStrings(String[] patterns, String word) { 3 | return (int) Arrays.stream(patterns).filter(pattern -> word.contains(pattern)).count(); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /solutions/2006. Count Number of Pairs With Absolute Difference K/2006.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countKDifference(self, nums: list[int], k: int) -> int: 3 | count = collections.Counter(nums) 4 | return sum(count[i] * count[i - k] for i in range(k + 1, 101)) 5 | -------------------------------------------------------------------------------- /solutions/2255. Count Prefixes of a Given String/2255.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int countPrefixes(vector& words, string s) { 4 | return ranges::count_if( 5 | words, [&](const string& word) { return s.find(word) == 0; }); 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /solutions/2357. Make Array Zero by Subtracting Equal Amounts/2357.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minimumOperations(vector& nums) { 4 | unordered_set seen(nums.begin(), nums.end()); 5 | return seen.size() - seen.contains(0); 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /solutions/2729. Check if The Number is Fascinating/2729.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isFascinating(int n) { 4 | string s = to_string(n) + to_string(2 * n) + to_string(3 * n); 5 | ranges::sort(s); 6 | return s == "123456789"; 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /solutions/2931. Maximum Spending After Buying Items/2931.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxSpending(self, values: list[list[int]]) -> int: 3 | items = sorted(item for shop in values for item in shop) 4 | return sum(item * d for d, item in enumerate(items, 1)) 5 | -------------------------------------------------------------------------------- /solutions/3146. Permutation Difference between Two Strings/3146.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findPermutationDifference(self, s: str, t: str) -> int: 3 | indices = {c: i for i, c in enumerate(s)} 4 | return sum([abs(indices[c] - i) for i, c in enumerate(t)]) 5 | -------------------------------------------------------------------------------- /solutions/3194. Minimum Average of Smallest and Largest Elements/3194.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumAverage(self, nums: list[int]) -> float: 3 | nums.sort() 4 | return min((nums[i] + nums[~i]) / 2 5 | for i in range(len(nums) // 2 + 1)) 6 | -------------------------------------------------------------------------------- /solutions/3405. Count the Number of Arrays with K Matching Adjacent Elements/3405.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countGoodArrays(self, n: int, m: int, k: int) -> int: 3 | MOD = 1_000_000_007 4 | return m * pow(m - 1, n - k - 1, MOD) * math.comb(n - 1, k) % MOD 5 | -------------------------------------------------------------------------------- /solutions/461. Hamming Distance/461.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def hammingDistance(self, x: int, y: int) -> int: 3 | ans = 0 4 | 5 | while x > 0 or y > 0: 6 | ans += (x & 1) ^ (y & 1) 7 | x >>= 1 8 | y >>= 1 9 | 10 | return ans 11 | -------------------------------------------------------------------------------- /solutions/528. Random Pick with Weight/528-2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def __init__(self, w: list[int]): 3 | self.prefix = list(itertools.accumulate(w)) 4 | 5 | def pickIndex(self) -> int: 6 | return bisect_left(self.prefix, random.random() * self.prefix[-1]) 7 | -------------------------------------------------------------------------------- /solutions/614. Second Degree Follower/614.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | Follower.follower, 3 | COUNT(DISTINCT Followee.follower) AS num 4 | FROM Follow AS Follower 5 | INNER JOIN Follow AS Followee 6 | ON (Follower.follower = Followee.followee) 7 | GROUP BY 1 8 | ORDER BY 1; 9 | -------------------------------------------------------------------------------- /solutions/884. Uncommon Words from Two Sentences/884.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def uncommonFromSentences(self, A: str, B: str) -> list[str]: 3 | count = collections.Counter((A + ' ' + B).split()) 4 | return [word for word, freq in count.items() if freq == 1] 5 | -------------------------------------------------------------------------------- /solutions/1072. Flip Columns For Maximum Number of Equal Rows/1072.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxEqualRowsAfterFlips(self, matrix: list[list[int]]) -> int: 3 | patterns = [tuple(a ^ row[0] for a in row) for row in matrix] 4 | return max(Counter(patterns).values()) 5 | -------------------------------------------------------------------------------- /solutions/1078. Occurrences After Bigram/1078.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findOcurrences(self, text: str, first: str, second: str) -> list[str]: 3 | words = text.split() 4 | return [c for a, b, c in zip(words, words[1:], words[2:]) if a == first and b == second] 5 | -------------------------------------------------------------------------------- /solutions/1256. Encode Number/1256.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string encode(int num) { 4 | string binaryStr = bitset<30>(num + 1).to_string(); 5 | binaryStr.erase(0, binaryStr.find_first_not_of('0')); 6 | return binaryStr.substr(1); 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /solutions/1304. Find N Unique Integers Sum up to Zero/1304.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] sumZero(int n) { 3 | int[] ans = new int[n]; 4 | 5 | for (int i = 0; i < n; ++i) 6 | ans[i] = i * 2 - n + 1; 7 | 8 | return ans; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /solutions/1317. Convert Integer to the Sum of Two No-Zero Integers/1317.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def getNoZeroIntegers(self, n: int) -> list[int]: 3 | for A in range(n): 4 | B = n - A 5 | if '0' not in str(A) and '0' not in str(B): 6 | return A, B 7 | -------------------------------------------------------------------------------- /solutions/137. Single Number II/137-2.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def singleNumber(self, nums: list[int]) -> int: 3 | ones = 0 4 | twos = 0 5 | 6 | for num in nums: 7 | ones ^= (num & ~twos) 8 | twos ^= (num & ~ones) 9 | 10 | return ones 11 | -------------------------------------------------------------------------------- /solutions/1708. Largest Subarray Length K/1708.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector largestSubarray(vector& nums, int k) { 4 | const auto it = max_element(nums.begin(), nums.end() - k + 1); 5 | return std::vector(it, it + k); 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /solutions/1715. Count Apples and Oranges/1715.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | SUM(Boxes.apple_count + IFNULL(Chests.apple_count, 0)) AS apple_count, 3 | SUM(Boxes.orange_count + IFNULL(Chests.orange_count, 0)) AS orange_count 4 | FROM Boxes 5 | LEFT JOIN Chests 6 | USING (chest_id); 7 | -------------------------------------------------------------------------------- /solutions/1732. Find the Highest Altitude/1732.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def largestAltitude(self, gain: list[int]) -> int: 3 | ans = 0 4 | currAltitude = 0 5 | for g in gain: 6 | currAltitude += g 7 | ans = max(ans, currAltitude) 8 | return ans 9 | -------------------------------------------------------------------------------- /solutions/1893. Check if All the Integers in a Range Are Covered/1893.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isCovered(self, ranges: list[list[int]], left: int, right: int) -> bool: 3 | return all(any(l <= i <= r for l, r in ranges) for i in range( 4 | left, right + 1)) 5 | -------------------------------------------------------------------------------- /solutions/191. Number of 1 Bits/191.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int hammingWeight(uint32_t n) { 4 | int ans = 0; 5 | 6 | for (int i = 0; i < 32; ++i) 7 | if ((n >> i) & 1) 8 | ++ans; 9 | 10 | return ans; 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /solutions/2351. First Letter to Appear Twice/2351.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def repeatedCharacter(self, s: str) -> str: 3 | seen = [False] * 26 4 | 5 | for c in s: 6 | if seen[ord(c) - ord('a')]: 7 | return c 8 | seen[ord(c) - ord('a')] = True 9 | -------------------------------------------------------------------------------- /solutions/2390. Removing Stars From a String/2390.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def removeStars(self, s: str) -> str: 3 | ans = [] 4 | for c in s: 5 | if c == '*': 6 | ans.pop() 7 | else: 8 | ans.append(c) 9 | return ''.join(ans) 10 | -------------------------------------------------------------------------------- /solutions/2418. Sort the People/2418.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def sortPeople(self, names: list[str], heights: list[int]) -> list[str]: 3 | return [height for _, height in 4 | sorted([(height, name) for name, height in zip(names, heights)], reverse=True)] 5 | -------------------------------------------------------------------------------- /solutions/2619. Array Prototype Last/2619.ts: -------------------------------------------------------------------------------- 1 | declare global { 2 | interface Array { 3 | last(): T | -1; 4 | } 5 | } 6 | 7 | Array.prototype.last = function () { 8 | return this.length === 0 ? -1 : this[this.length - 1]; 9 | }; 10 | 11 | export {}; 12 | -------------------------------------------------------------------------------- /solutions/27. Remove Element/27.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int removeElement(int[] nums, int val) { 3 | int i = 0; 4 | 5 | for (final int num : nums) 6 | if (num != val) 7 | nums[i++] = num; 8 | 9 | return i; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /solutions/2733. Neither Minimum nor Maximum/2733.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int findNonMinOrMax(vector& nums) { 4 | if (nums.size() < 3) 5 | return -1; 6 | sort(nums.begin(), nums.begin() + 3); 7 | return nums[1]; 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /solutions/2745. Construct the Longest New String/2745.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int longestString(int x, int y, int z) { 3 | final int mn = Math.min(x, y); 4 | if (x == y) 5 | return (mn * 2 + z) * 2; 6 | return (mn * 2 + 1 + z) * 2; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /solutions/2923. Find Champion I/2923-2.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int findChampion(int[][] grid) { 3 | for (int i = 0; i < grid.length; ++i) 4 | if (Arrays.stream(grid[i]).sum() == grid.length - 1) 5 | return i; 6 | return -1; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /solutions/3014. Minimum Number of Pushes to Type Word I/3014.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minimumPushes(self, word: str) -> int: 3 | freqs = sorted(collections.Counter(word).values(), reverse=True) 4 | return sum(freq * (i // 8 + 1) for i, freq in enumerate(freqs)) 5 | -------------------------------------------------------------------------------- /solutions/3084. Count Substrings Starting and Ending with Given Character/3084.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public long countSubstrings(String s, char c) { 3 | final long freq = s.chars().filter(ch -> ch == c).count(); 4 | return freq * (freq + 1) / 2; 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /solutions/3110. Score of a String/3110.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int scoreOfString(string s) { 4 | int ans = 0; 5 | 6 | for (int i = 1; i < s.length(); ++i) 7 | ans += abs(s[i] - s[i - 1]); 8 | 9 | return ans; 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /solutions/3162. Find the Number of Good Pairs I/3162.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numberOfPairs(self, nums1: list[int], nums2: list[int], k: int) -> int: 3 | return sum(num1 % (num2 * k) == 0 4 | for num1 in nums1 5 | for num2 in nums2) 6 | -------------------------------------------------------------------------------- /solutions/559. Maximum Depth of N-ary Tree/559.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxDepth(self, root: 'Node') -> int: 3 | if not root: 4 | return 0 5 | if not root.children: 6 | return 1 7 | return 1 + max(self.maxDepth(child) for child in root.children) 8 | -------------------------------------------------------------------------------- /solutions/746. Min Cost Climbing Stairs/746.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minCostClimbingStairs(self, cost: list[int]) -> int: 3 | cost.append(0) 4 | 5 | for i in range(2, len(cost)): 6 | cost[i] += min(cost[i - 1], cost[i - 2]) 7 | 8 | return cost[-1] 9 | -------------------------------------------------------------------------------- /solutions/775. Global and Local Inversions/775-2.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean isIdealPermutation(int[] nums) { 3 | for (int i = 0; i < nums.length; ++i) 4 | if (Math.abs(nums[i] - i) > 1) 5 | return false; 6 | return true; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /solutions/836. Rectangle Overlap/836.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isRectangleOverlap(vector& rec1, vector& rec2) { 4 | return rec1[0] < rec2[2] && rec2[0] < rec1[2] && // 5 | rec1[1] < rec2[3] && rec2[1] < rec1[3]; 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /solutions/933. Number of Recent Calls/933.cpp: -------------------------------------------------------------------------------- 1 | class RecentCounter { 2 | public: 3 | int ping(int t) { 4 | q.push(t); 5 | while (q.front() < t - 3000) 6 | q.pop(); 7 | return q.size(); 8 | } 9 | 10 | private: 11 | queue q; 12 | }; 13 | -------------------------------------------------------------------------------- /solutions/1037. Valid Boomerang/1037.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def isBoomerang(self, points: list[list[int]]) -> bool: 3 | return ((points[1][0] - points[0][0]) * (points[2][1] - points[1][1]) != 4 | (points[1][1] - points[0][1]) * (points[2][0] - points[1][0])) 5 | -------------------------------------------------------------------------------- /solutions/1076. Project Employees II/1076.sql: -------------------------------------------------------------------------------- 1 | WITH 2 | RankedProjects AS ( 3 | SELECT project_id, RANK() OVER(ORDER BY COUNT(*) DESC) AS `rank` 4 | FROM Project 5 | GROUP BY 1 6 | ) 7 | SELECT project_id 8 | FROM RankedProjects 9 | WHERE `rank` = 1; 10 | -------------------------------------------------------------------------------- /solutions/1137. N-th Tribonacci Number/1137-2.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int tribonacci(int n) { 3 | int[] dp = {0, 1, 1}; 4 | 5 | for (int i = 3; i <= n; ++i) 6 | dp[i % 3] = dp[0] + dp[1] + dp[2]; 7 | 8 | return dp[n % 3]; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /solutions/1158. Market Analysis I/1158.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | Users.user_id AS buyer_id, 3 | Users.join_date, 4 | COUNT(Orders.order_id) AS orders_in_2019 5 | FROM Users 6 | LEFT JOIN Orders 7 | ON (Users.user_id = Orders.buyer_id AND YEAR(order_date) = '2019') 8 | GROUP BY 1; 9 | -------------------------------------------------------------------------------- /solutions/1250. Check If It Is a Good Array/1250.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isGoodArray(vector& nums) { 4 | int g = nums[0]; 5 | 6 | for (const int num : nums) 7 | g = __gcd(g, num); 8 | 9 | return g == 1; 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /solutions/1637. Widest Vertical Area Between Two Points Containing No Points/1637.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def maxWidthOfVerticalArea(self, points: list[list[int]]) -> int: 3 | xs = sorted([x for x, _ in points]) 4 | return max(b - a for a, b in itertools.pairwise(xs)) 5 | -------------------------------------------------------------------------------- /solutions/1672. Richest Customer Wealth/1672.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int maximumWealth(int[][] accounts) { 3 | return Arrays.stream(accounts) 4 | .mapToInt(account -> Arrays.stream(account).sum()) 5 | .max() 6 | .getAsInt(); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /solutions/1957. Delete Characters to Make Fancy String/1957.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def makeFancyString(self, s: str) -> str: 3 | ans = [] 4 | for c in s: 5 | if len(ans) < 2 or ans[-1] != c or ans[-2] != c: 6 | ans.append(c) 7 | return ''.join(ans) 8 | -------------------------------------------------------------------------------- /solutions/2057. Smallest Index With Equal Value/2057.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int smallestEqual(vector& nums) { 4 | for (int i = 0; i < nums.size(); ++i) 5 | if (nums[i] == i % 10) 6 | return i; 7 | return -1; 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /solutions/2180. Count Integers With Even Digit Sum/2180.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countEven(self, num: int) -> int: 3 | return (num - self._getDigitSum(num) % 2) // 2 4 | 5 | def _getDigitSum(self, num: int) -> int: 6 | return sum(int(digit) for digit in str(num)) 7 | -------------------------------------------------------------------------------- /solutions/2185. Counting Words With a Given Prefix/2185.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int prefixCount(vector& words, string pref) { 4 | return ranges::count_if( 5 | words, [&](const string& word) { return word.find(pref) == 0; }); 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /solutions/2215. Find the Difference of Two Arrays/2215.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findDifference(self, nums1: list[int], 3 | nums2: list[int]) -> list[list[int]]: 4 | set1 = set(nums1) 5 | set2 = set(nums2) 6 | return [set1 - set2, set2 - set1] 7 | -------------------------------------------------------------------------------- /solutions/2221. Find Triangular Sum of an Array/2221.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def triangularSum(self, nums: list[int]) -> int: 3 | for sz in range(len(nums), 0, -1): 4 | for i in range(sz - 1): 5 | nums[i] = (nums[i] + nums[i + 1]) % 10 6 | return nums[0] 7 | -------------------------------------------------------------------------------- /solutions/2264. Largest 3-Same-Digit Number in String/2264.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def largestGoodInteger(self, num: str) -> str: 3 | return max(num[i - 2:i + 1] 4 | if num[i] == num[i - 1] == num[i - 2] 5 | else '' for i in range(2, len(num))) 6 | -------------------------------------------------------------------------------- /solutions/2283. Check if Number Has Equal Digit Count and Digit Value/2283.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def digitCount(self, num: str) -> bool: 3 | count = collections.Counter(num) 4 | return all(count[str(i)] == int(digit) 5 | for i, digit in enumerate(num)) 6 | -------------------------------------------------------------------------------- /solutions/2635. Apply Transform Over Each Element in Array/2635.ts: -------------------------------------------------------------------------------- 1 | function map(arr: number[], fn: (n: number, i: number) => number): number[] { 2 | const ans: number[] = []; 3 | arr.forEach((a, index) => { 4 | ans.push(fn(a, index)); 5 | }); 6 | return ans; 7 | } 8 | -------------------------------------------------------------------------------- /solutions/2636. Promise Pool/2636.ts: -------------------------------------------------------------------------------- 1 | type F = () => Promise; 2 | 3 | function promisePool(functions: F[], n: number): Promise { 4 | const next = () => functions[n++]?.().then(next); 5 | return Promise.all(functions.slice(0, n).map((f) => f().then(next))); 6 | } 7 | -------------------------------------------------------------------------------- /solutions/2652. Sum Multiples/2652.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int sumOfMultiples(int n) { 3 | int ans = 0; 4 | for (int i = 1; i <= n; ++i) 5 | if (i % 3 == 0 || i % 5 == 0 || i % 7 == 0) 6 | ans += i; 7 | return ans; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /solutions/2678. Number of Senior Citizens/2678.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int countSeniors(vector& details) { 4 | return ranges::count_if(details, [](const string& detail) { 5 | return stoi(detail.substr(11, 2)) > 60; 6 | }); 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /solutions/2678. Number of Senior Citizens/2678.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int countSeniors(String[] details) { 3 | return (int) Arrays.stream(details) 4 | .filter(detail -> Integer.parseInt(detail.substring(11, 13)) > 60) 5 | .count(); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /solutions/268. Missing Number/268.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int missingNumber(vector& nums) { 4 | int ans = nums.size(); 5 | 6 | for (int i = 0; i < nums.size(); ++i) 7 | ans ^= i ^ nums[i]; 8 | 9 | return ans; 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /solutions/2717. Semi-Ordered Permutation/2717.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def semiOrderedPermutation(self, nums: list[int]) -> int: 3 | n = len(nums) 4 | index1 = nums.index(1) 5 | indexN = nums.index(n) 6 | return index1 + (n - 1 - indexN) - int(index1 > indexN) 7 | -------------------------------------------------------------------------------- /solutions/2890. Reshape Data: Melt/2890.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | 4 | def meltTable(report: pd.DataFrame) -> pd.DataFrame: 5 | return pd.melt( 6 | report, 7 | id_vars=['product'], 8 | var_name='quarter', 9 | value_name='sales', 10 | ) 11 | -------------------------------------------------------------------------------- /solutions/2917. Find the K-or of an Array/2917.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def findKOr(self, nums: list[int], k: int) -> int: 3 | MAX_BIT = 30 4 | return sum(2**i 5 | for i in range(MAX_BIT + 1) 6 | if sum(num >> i & 1 for num in nums) >= k) 7 | -------------------------------------------------------------------------------- /solutions/2979. Most Expensive Item That Can Not Be Bought/2979.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int mostExpensiveItem(int primeOne, int primeTwo) { 3 | // https://en.wikipedia.org/wiki/Coin_problem 4 | return primeOne * primeTwo - primeOne - primeTwo; 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /solutions/3417. Zigzag Grid Traversal With Skip/3417.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def zigzagTraversal(self, grid: list[list[int]]) -> list[int]: 3 | zigzag = [row[::-1] if i % 2 else row for i, row in enumerate(grid)] 4 | return [num for row in zigzag for num in row][::2] 5 | -------------------------------------------------------------------------------- /solutions/387. First Unique Character in a String/387.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def firstUniqChar(self, s: str) -> int: 3 | count = collections.Counter(s) 4 | 5 | for i, c in enumerate(s): 6 | if count[c] == 1: 7 | return i 8 | 9 | return -1 10 | -------------------------------------------------------------------------------- /solutions/1217. Play with Chips/1217.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int minCostToMoveChips(vector& position) { 4 | vector count(2); 5 | for (const int p : position) 6 | ++count[p % 2]; 7 | return min(count[0], count[1]); 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /solutions/1290. Convert Binary Number in a Linked List to Integer/1290.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def getDecimalValue(self, head: ListNode) -> int: 3 | ans = 0 4 | 5 | while head: 6 | ans = ans * 2 + head.val 7 | head = head.next 8 | 9 | return ans 10 | -------------------------------------------------------------------------------- /solutions/1304. Find N Unique Integers Sum up to Zero/1304.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector sumZero(int n) { 4 | vector ans(n); 5 | 6 | for (int i = 0; i < n; ++i) 7 | ans[i] = i * 2 - n + 1; 8 | 9 | return ans; 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /solutions/1550. Three Consecutive Odds/1550.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def threeConsecutiveOdds(self, arr: list[int]) -> bool: 3 | count = 0 4 | for a in arr: 5 | count = 0 if a % 2 == 0 else count + 1 6 | if count == 3: 7 | return True 8 | return False 9 | -------------------------------------------------------------------------------- /solutions/1558. Minimum Numbers of Function Calls to Make Target Array/1558.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minOperations(self, nums: list[int]) -> int: 3 | mx = max(nums) 4 | return (sum(num.bit_count() for num in nums) + 5 | (0 if mx == 0 else mx.bit_length() - 1)) 6 | -------------------------------------------------------------------------------- /solutions/1812. Determine Color of a Chessboard Square/1812.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool squareIsWhite(string coordinates) { 4 | const char letter = coordinates[0]; 5 | const char digit = coordinates[1]; 6 | return letter % 2 != digit % 2; 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /solutions/1816. Truncate Sentence/1816.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string truncateSentence(string s, int k) { 4 | for (int i = 0; i < s.length(); ++i) 5 | if (s[i] == ' ' && --k == 0) 6 | return s.substr(0, i); 7 | return s; 8 | } 9 | }; 10 | -------------------------------------------------------------------------------- /solutions/2133. Check if Every Row and Column Contains All Numbers/2133.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def checkValid(self, matrix: list[list[int]]) -> bool: 3 | return all(min(len(set(row)), len(set(col))) == len(matrix) 4 | for row, col in zip(matrix, zip(*matrix))) 5 | -------------------------------------------------------------------------------- /solutions/2186. Minimum Number of Steps to Make Two Strings Anagram II/2186.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minSteps(self, s: str, t: str) -> int: 3 | count = collections.Counter(s) 4 | count.subtract(collections.Counter(t)) 5 | return sum([abs(c) for c in count.values()]) 6 | -------------------------------------------------------------------------------- /solutions/2544. Alternating Digit Sum/2544.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def alternateDigitSum(self, n: int) -> int: 3 | ans = 0 4 | sign = 1 5 | 6 | while n > 0: 7 | sign *= -1 8 | ans += n % 10 * sign 9 | n //= 10 10 | 11 | return sign * ans 12 | -------------------------------------------------------------------------------- /solutions/2605. Form Smallest Number From Two Digit Arrays/2605.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minNumber(self, nums1: list[int], nums2: list[int]) -> int: 3 | return min(a if a == b else min(a, b) * 10 + max(a, b) 4 | for a in nums1 5 | for b in nums2) 6 | -------------------------------------------------------------------------------- /solutions/2652. Sum Multiples/2652.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int sumOfMultiples(int n) { 4 | int ans = 0; 5 | for (int i = 1; i <= n; ++i) 6 | if (i % 3 == 0 || i % 5 == 0 || i % 7 == 0) 7 | ans += i; 8 | return ans; 9 | } 10 | }; 11 | -------------------------------------------------------------------------------- /solutions/27. Remove Element/27.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int removeElement(vector& nums, int val) { 4 | int i = 0; 5 | 6 | for (const int num : nums) 7 | if (num != val) 8 | nums[i++] = num; 9 | 10 | return i; 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /solutions/2979. Most Expensive Item That Can Not Be Bought/2979.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int mostExpensiveItem(int primeOne, int primeTwo) { 4 | // https://en.wikipedia.org/wiki/Coin_problem 5 | return primeOne * primeTwo - primeOne - primeTwo; 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /solutions/3084. Count Substrings Starting and Ending with Given Character/3084.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | long long countSubstrings(string s, char c) { 4 | const int freq = ranges::count(s, c); 5 | return static_cast(freq) * (freq + 1) / 2; 6 | } 7 | }; 8 | -------------------------------------------------------------------------------- /solutions/3110. Score of a String/3110.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int scoreOfString(String s) { 3 | int ans = 0; 4 | 5 | for (int i = 1; i < s.length(); ++i) 6 | ans += Math.abs(s.charAt(i) - s.charAt(i - 1)); 7 | 8 | return ans; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /solutions/3151. Special Array I/3151.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isArraySpecial(vector& nums) { 4 | for (int i = 1; i < nums.size(); ++i) 5 | if (nums[i] % 2 == nums[i - 1] % 2) 6 | return false; 7 | return true; 8 | } 9 | }; 10 | --------------------------------------------------------------------------------