Coding Questions
30/09/2025
Leetcode question 2221. Find Triangular Sum of an Array
- Solution
Editorial
Compute each sub layer then return when the layer size is 1.
28/09/2025
Leetcode question 976. Largest Perimeter Triangle
- Solution
Editorial
Sort the points then iterate through all triplets adjacent to each other.
27/09/2025
Leetcode question 812. Largest Triangle Area
- Solution
Editorial
Iterate through all pairs of points and ensure they are valid then call the max_area.
25/09/2025
Leetcode question 120. Triangle
- Solution
Editorial
2D dp. 2 possible child nodes for each element in the tree. Went up the triangle to reduce end computations.
9/09/2025
Leetcode question 2327. Number of People Aware of a Secret
- Solution
Editorial
2D dp. Annoying part is doing forget and sharing. The bounds of the two are a bit finnicky.
7/09/2025
Leetcode question 1304. Find N Unique Integers Sum up to Zero
- Solution
Editorial
Insert n - 1 unique numbers then insert the negative.
5/09/2025
Leetcode question 1584. Min Cost to Connect All Points
- Solution
Editorial
Find the mst of the points after computing edge weights.
Leetcode question 990. Satisfiability of Equality Equations
- Solution
Editorial
Find DSU of the equality tree then check the inequalities.
4/09/2025
Leetcode question 146. LRU Cache
- Solution
Editorial
Uses maps and linked lists. Refer to lists in std lib.
Leetcode question 3516. Find Closest Person
- Solution
Editorial
Stock standard absolute value check and difference.
2/09/2025
Leetcode question 3025. Find the Number of Ways to Place People I
- Solution
Editorial
Some checks whether the pair is valid then if every node is outside. O(n^3) time is brute forceable.
Codeforces Contest 2132
- A
- Solution
Editorial
This question was append or prepend to a string depending on v and d.
- B
- Solution
Editorial
The question was to determine if the number was divisible by a value 10^x + 1 and store them.
- C1
- Solution
Editorial
The minimum amount of orders is determining the remainder mod 3^x for all x and summing them together.
- C2
- Solution
Editorial
For any combination, breaking an order into 3 smaller orders is cheaper. Thus we need to determine the minimum number of orders then break larger orders into smaller depending on how many orders are available.
- E
- Solution
Editorial
Interesting question. Required to use the hints. Initial thoughts was decreasing values and dual graphs and summation of the two graphs. However because it is not a linear function we can not binary search.
After looking at the solutions I realised the main problem was that I was trying to work from a base set of values then expand. The solution was to overestimate x and y then decrease them to fit the limit.
1/09/2025
Leetcode question 1792. Maximum Average Pass Ratio
- Solution
Editorial
Greedy with max heap properties.
Proof would be for any combination of extra students. Put them where it will increase the ratio the most. For any other deviation from the optimal, the return of ratio increase would be worst.
30/08/2025
Leetcode question 36. Valid Sudoku
- Solution
Editorial
Check first rows, then columns then the subsquares.
29/08/2025
Leetcode question 3021. Alice and Bob Playing Flower Game
- Solution
Editorial
The pair is valid if the sum of flowers is odd. So count the number of odds pairs for any combination of n and m. Which can be done with some modulus and maths.
28/08/2025
Leetcode question 3446. Sort Matrix by Diagonals
- Solution
Editorial
Break it down into 2 sets and get the numbers, sort them then reinsert
Codeforces Contest 2136
- A
- Solution
Editorial
The answer is to ensure that for any given half, a team's score for the half is not greater then a value (as shown in the code).
- B
- Solution
Editorial
Sliding window question. If for any string of length k, there is no '0' then at least one of them must be maximum and thus it would be invalid.
- C
- Solution
Editorial
Using a map, a queue and a best_so_far, we can use DP to determine whether using a new neat array is better or worse then not using it.
26/08/2025
Leetcode question 3000. Maximum Area of Longest Diagonal Rectangle
- Solution
Editorial
Eval the max value and swap if it is greater
Codeforces Contest 2134
- A
- Solution
Editorial
Modulus check on the numbers and coverage check.
- B
- Solution
Editorial
Was a modulus check in mod k + 1. Each addition decreases the remainder of mod k + 1 by 1.
- C
- Solution
Editorial
2 things are important. The predecessor and successor at event indices.
Greedy so you make the predecessor legal when compared to the current and then the successor legal when comparing the current by the succ and pred.
24/08/2025
Leetcode question 1493. Longest Subarray of 1’s After Deleting One Element
- Solution
Editorial
Predecessors and successors counting. Edge case encountered where the index 0 or last element is deleted. Also made errors in my own code on how it should work.
Codeforces Contest 2133
- A
- Solution
Editorial
Check if two numbers are the same.
- B
- Solution
Editorial
Sort decreasing then sum every odd number.
- C
- Solution
Editorial
Weird question which required topological ordering, path lengths then adjacency checks.
First find the longest paths, then check for valid next nodes with length minus 1.
Codeforces Contest 2034
- A
- Solution
- https://www.youtube.com/watch?v=XZSsTcJzayc
Editorial
This is a question to find the LCM of the two numbers.
- B
- Solution
- https://www.youtube.com/watch?v=k5cUNLMUClQ
Editorial
Need a check on whether the last x where 0 which could be done iteratively then solve from there
25/05/2025
Leetcode question 2131. Longest Palindrome by Concatenating Two Letter Words
- Solution
Editorial
Interesting question. One edge case to handle are duplicate letters in the pair which is doable by having a seperate case. Can sort the string to find duplicates. Had an error with my multiplication though.
24/05/2025
Leetcode question 2942. Find Words Containing Character
- Solution
Editorial
Simple question just use contains on the string or iterate through the string.
23/05/2025
Leetcode question 3068. Find the Maximum Sum of Node Values
- Solution
Editorial
Interesting question. First instinct was to DP but after realising that there are certain conditions such as having an even number of flips across the tree it becomes easier.
22/05/2025
Leetcode question 3362. Zero Array Transformation III
- Solution
Editorial
The trick is to iterate on the numbers array. In doing so you ensure you find the minimum amount of queries possible for a given value with the maximum range. Usint pqs helps but you need to use checks to ensure whether it is possible.
21/05/2025
Leetcode question 73. Set Matrix Zeroes
- Solution
Editorial
Initial thought was if a value was 0, set all values in its column and row to 0 however this is too slow. i.e. multiple 0s in a row or column. To speed this up cache the 0 indexes and iterate through the cached 0s without duplicates and set those columns and rows to 0.
20/05/2025
Leetcode question 3355. Zero Array Transformation I
- Solution
Editorial
Question is a matter of caching the increment and decrement ranges and then doing 1 parse on the nums array.
19/05/2025
Leetcode question 3024. Type of Triangle
- Solution
Editorial
Very easy question. Only tricky part is that if the sum of 2 lengths is less then the third it cannot be a triangle.
Codeforces Contest 2109
- A
- Solution
Editorial
There are 2 situations where it is not true. For every set of numbers, at least 1 person must lose and for each pair of people at least 1 person must win.
- B
- Solution
Editorial
In a 2D plane, we can either initially cut the x or y from the starting position. Initially thought of doing complex mathematics to do it but realised I could do them individually and compare the result.
- C
- Solution
Editorial
Weird question........ Idk look at the official editorial.
18/05/2025
Leetcode question 1931. Painting a Grid With Three Different Colors
- Solution
Editorial
DP with bitwise operations and masks. A little annoying to get the checks working and I did the DP wrong. One optimisation is caching the valid candidates for sets of 5 colours which was necessary as my code was slow. I guess you could also cache the valid combinations which will cut down the number of operations by a decent amount but this solution works.
17/05/2025
Leetcode question 75. Sort Colors
- Solution
Editorial
Simplest solution is a counting sort as there are only 3 possible values.
16/05/2025
Leetcode question 2901. Longest Unequal Adjacent Groups Subsequence II
15/05/2025
Leetcode question 2900. Longest Unequal Adjacent Groups Subsequence I
13/05/2025
Leetcode question 3335. Total Characters in String After Transformations I
12/05/2025
Leetcode question 2094. Finding 3-Digit Even Numbers
11/05/2025
Leetcode question 1550. Three Consecutive Odds
Codeforces Contest 2102
8/05/2025
Leetcode question 3342. Find Minimum Time to Reach Last Room II
7/05/2025
Leetcode question 3341. Find Minimum Time to Reach Last Room I
6/05/2025
Leetcode question 1920. Build Array from Permutation
5/05/2025
Leetcode question 790. Domino and Tromino Tiling
4/05/2025
Leetcode question 1128. Number of Equivalent Domino Pairs
Codeforces Contest 2103
3/05/2025
Leetcode question 1007. Minimum Domino Rotations For Equal Row
2/05/2025
Leetcode question 838. Push Dominoes
30/04/2025
Leetcode question 1295. Find Numbers with Even Number of Digits
27/04/2025
Leetcode question 3392. Count Subarrays of Length Three With a Condition
23/04/2025
Leetcode question 1399. Count Largest Group
21/04/2025
Leetcode question 2145. Count the Hidden Sequences
Codeforces Contest 2103
20/04/2025
Leetcode question 781. Rabbits in Forest
Codeforces Contest 2096
17/04/2025
Leetcode question 2176. Count Equal and Divisible Pairs in an Array
14/04/2025
Leetcode question 1534. Count Good Triplets
13/04/2025
Leetcode question 1922. Count Good Numbers
Codeforces Contest 2093
9/04/2025
Leetcode question 3375. Minimum Operations to Make Array Values Equal to K
8/04/2025
Leetcode question 3396. Minimum Number of Operations to Make Elements in Array Distinct
2/04/2025
Leetcode question 2873. Maximum Value of an Ordered Triplet I
1/04/2025
Leetcode question 2140. Solving Questions With Brainpower
20/03/2025
Leetcode question 3108. Minimum Cost Walk in Weighted Graph
19/03/2025
Leetcode question 3191. Minimum Operations to Make Binary Array Elements Equal to One I
17/03/2025
Leetcode question 2206. Divide Array Into Equal Pairs
16/03/2025
Leetcode question 2594. Minimum Time to Repair Cars
15/03/2025
Leetcode question 2560. House Robber IV
14/03/2025
Leetcode question 2226. Maximum Candies Allocated to K Children
13/03/2025
Leetcode question 3356. Zero Array Transformation II
12/03/2025
Leetcode question 2529. Maximum Count of Positive Integer and Negative Integer
11/03/2025
Leetcode question 1358. Number of Substrings Containing All Three Characters
Codeforces Contest 2074
05/03/2025
Leetcode question 2579. Count Total Number of Colored Cells
04/03/2025
Leetcode question 1780. Check if Number is a Sum of Powers of Three
Codeforces Contest 2067
13/02/2025
Leetcode question 3066. Minimum Operations to Exceed Threshold Value II
11, 12: Preparation for IMC contest and participation in CPMSOC contest
10/02/2025
Leetcode question 3174. Clear Digits
09/02/2025
Leetcode question 2364. Count Number of Bad Pairs
Codeforces Contest 2063
08/02/2025
Leetcode question 1249. Minimum Remove to Make Valid Parentheses
Leetcode question 2349. Design a Number Container System
07/02/2025
Leetcode question 3160. Find the Number of Distinct Colors Among the Balls
06/02/2025
Leetcode question 1726. Tuple with Same Product
Codeforces Contest 2062
05/02/2025
Leetcode question 1790. Check if One String Swap Can Make Strings Equal
04/02/2025
Leetcode question 1800. Maximum Ascending Subarray Sum
03/02/2025
Leetcode question 3105. Longest Strictly Increasing or Strictly Decreasing Subarray
Codeforces Contest 2059
02/02/2025
Leetcode question 1752. Check if Array Is Sorted and Rotated
15/1/2025
Leetcode question 2429. Minimize XOR
14/1/2025
Leetcode question 2657. Find the Prefix Common Array of Two Arrays
13/1/2025
Leetcode question 3223. Minimum Length of String After Operations
12/1/2025
Leetcode question 2116. Check if a Parentheses String Can Be Valid
- Kind of difficult and interesting question.
- Solution
11/1/2025
Leetcode question 1400. Construct K Palindrome Strings
10/1/2025
Leetcode question 916. Word Subsets
9/1/2025
Leetcode question 2185. Counting Words With a Given Prefix
Codeforces Contest 2057
8/1/2025
Leetcode question 3042. Count Prefix and Suffix Pairs I
7/1/2025
Leetcode question 1408. String Matching in an Array
6/1/2025
Leetcode question 1769. Minimum Number of Operations to Move All Balls to Each Box
Codeforces Contest 2057
5/1/2025
Leetcode question 2381. Shifting Letters II
- Solution
- Interesting problem with char overflow
4/1/2025
Leetcode question 1930. Unique Length-3 Palindromic Subsequences
3/1/2025
Leetcode question 2270. Number of Ways to Split Array
Codeforces Contest 2024-2025 ICPC, NERC, Northern Eurasia Finals (Unrated, Online Mirror, ICPC Rules, Teams Preferred)
2/1/2025
Leetcode question 2559. Count Vowel Strings in Ranges
30/12/2024
Leetcode question 2466. Count Ways To Build Good Strings
27/12/2024
Leetcode question 1014. Best Sightseeing Pair
26/12/2024
Leetcode question 494. Target Sum
25/12/2024
Leetcode question 515. Find Largest Value in Each Tree Row
23/12/2024
Advent Of Code Day 4
22/12/2024
Advent Of Code Day 3
- Solution A
- Solution B
- Author’s note: Look at 3B comments. A lot of subfiles were used to make the process easier
21/12/2024
Leetcode question 2872. Maximum Number of K-Divisible Components
20/12/2024
Advent Of Code Day 19
Advent Of Code Day 1
Advent Of Code Day 2
19/12/2024
Leetcode question 769. Max Chunks To Make Sorted
17/12/2024
Leetcode question 3264. Final Array State After K Multiplication Operations I
12/12/2024
Leetcode question 2558 - Take Gifts From the Richest Pile
Advent Of Code Day 12
10/12/2024
Leetcode question 2981 - Find Longest Special Substring That Occurs Thrice II
09/12/2024
Leetcode question 3152 - Special Array II
Codeforces Contest 992
08/12/2024
Leetcode question 2054 - Two Best Non-Overlapping Events