Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve #3

Merged
merged 50 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
8d1d9f6
Delete Greatest Value in Each Row
hikjik Oct 18, 2023
ee9efe7
Parallel Courses III
hikjik Oct 18, 2023
9345a69
Parallel Courses II
hikjik Oct 18, 2023
1fc245e
Maximum Value of a String in an Array
hikjik Oct 18, 2023
2996e02
Circular Sentence
hikjik Oct 18, 2023
72efa76
Find the Pivot Integer
hikjik Oct 18, 2023
5e7ed31
Minimum Cuts to Divide a Circle
hikjik Oct 18, 2023
8dbdbd1
Number of Unequal Triplets in Array
hikjik Oct 18, 2023
5b8e776
Convert the Temperature
hikjik Oct 18, 2023
122c947
Number of Distinct Averages
hikjik Oct 18, 2023
1fa8a99
Apply Operations to an Array
hikjik Oct 18, 2023
9a4dae5
Average Value of Even Numbers That Are Divisible by Three
hikjik Oct 18, 2023
3ae065f
Separate the Digits in an Array
hikjik Oct 18, 2023
76fb0b2
Count Distinct Numbers on Board
hikjik Oct 18, 2023
db0983c
Alternating Digit Sum
hikjik Oct 18, 2023
f117fbe
Minimum Common Value
hikjik Oct 18, 2023
4896ba0
Maximum Count of Positive Integer and Negative Integer
hikjik Oct 18, 2023
52b0c21
Categorize Box According to Criteria
hikjik Oct 18, 2023
7620a61
Count the Digits That Divide a Number
hikjik Oct 18, 2023
1c17581
Count Pairs Of Similar Strings
hikjik Oct 18, 2023
b6bacad
Shortest Distance to Target String in a Circular Array
hikjik Oct 18, 2023
2d92309
Maximum Enemy Forts That Can Be Captured
hikjik Oct 18, 2023
4c1e3b3
Take Gifts From the Richest Pile
hikjik Oct 18, 2023
9fe414c
Find the Array Concatenation Value
hikjik Oct 18, 2023
f78b36a
Maximum Difference by Remapping a Digit
hikjik Oct 18, 2023
728a97b
Merge Two 2D Arrays by Summing Values
hikjik Oct 18, 2023
5ca1228
Split With Minimum Sum
hikjik Oct 18, 2023
80f6150
Pass the Pillow
hikjik Oct 18, 2023
4bfdcd6
Count the Number of Vowel Strings in Range
hikjik Oct 18, 2023
602af7e
Number of Even and Odd Bits
hikjik Oct 18, 2023
8ec5e0b
K Items With the Maximum Sum
hikjik Oct 18, 2023
17e9da2
Form Smallest Number From Two Digit Arrays
hikjik Oct 18, 2023
8a3af1d
Distribute Money to Maximum Children
hikjik Oct 18, 2023
855f63b
Prime In Diagonal
hikjik Oct 18, 2023
c5e1a60
Find the Width of Columns of a Grid
hikjik Oct 18, 2023
437bff7
Row With Maximum Ones
hikjik Oct 18, 2023
69aa8e9
Add Two Integers
hikjik Oct 18, 2023
c1926df
Root Equals Sum of Children
hikjik Oct 18, 2023
5ef196e
Find the Maximum Divisibility Score
hikjik Oct 18, 2023
377ed1c
Calculate Delayed Arrival Time
hikjik Oct 18, 2023
b014df0
Sum Multiples
hikjik Oct 18, 2023
b077c82
Maximum Sum With Exactly K Elements
hikjik Oct 18, 2023
473de7b
Number of Senior Citizens
hikjik Oct 18, 2023
c96cd60
Find the Distinct Difference Array
hikjik Oct 18, 2023
cd090e9
Find the Longest Balanced Substring of a Binary String
hikjik Oct 18, 2023
17e9598
Find the Losers of the Circular Game
hikjik Oct 18, 2023
5ad5e2c
Fix tests
hikjik Oct 18, 2023
0fbd8c2
Find Closest Number to Zero
hikjik Oct 18, 2023
c3ae615
Update CI
hikjik Oct 18, 2023
697a43f
Largest Number After Digit Swaps by Parity
hikjik Oct 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
strategy:
matrix:
type: ['RelWithDebInfo']
os: ['ubuntu-20.04']
os: ['ubuntu-22.04']

steps:
- name: Clone repo
Expand Down
48 changes: 48 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ add_task(add-binary)
add_task(add-digits)
add_task(add-strings)
add_task(add-to-array-form-of-integer)
add_task(add-two-integers)
add_task(add-two-numbers)
add_task(add-two-numbers-ii)
add_task(all-nodes-distance-k-in-binary-tree)
add_task(all-paths-from-source-to-target)
add_task(all-possible-full-binary-trees)
add_task(alternating-digit-sum)
add_task(apply-operations-to-an-array)
add_task(arithmetic-slices)
add_task(arithmetic-subarrays)
add_task(arranging-coins)
Expand All @@ -45,6 +48,7 @@ add_task(assign-cookies)
add_task(asteroid-collision)
add_task(average-of-levels-in-binary-tree)
add_task(average-salary-excluding-the-minimum-and-maximum-salary)
add_task(average-value-of-even-numbers-that-are-divisible-by-three)
add_task(avoid-flood-in-the-city)
add_task(backspace-string-compare)
add_task(balanced-binary-tree)
Expand Down Expand Up @@ -79,11 +83,13 @@ add_task(bulls-and-cows)
add_task(bus-routes)
add_task(buy-two-chocolates)
add_task(calculate-amount-paid-in-taxes)
add_task(calculate-delayed-arrival-time)
add_task(calculate-digit-sum-of-a-string)
add_task(can-make-arithmetic-progression-from-sequence)
add_task(can-place-flowers)
add_task(candy)
add_task(capacity-to-ship-packages-within-d-days)
add_task(categorize-box-according-to-criteria)
add_task(champagne-tower)
add_task(cheapest-flights-within-k-stops)
add_task(check-completeness-of-a-binary-tree)
Expand All @@ -102,6 +108,7 @@ add_task(check-if-there-is-a-valid-partition-for-the-array)
add_task(checking-existence-of-edge-length-limited-paths)
add_task(cherry-pickup)
add_task(cherry-pickup-ii)
add_task(circular-sentence)
add_task(climbing-stairs)
add_task(clone-graph)
add_task(coin-change)
Expand All @@ -124,22 +131,27 @@ add_task(convert-a-number-to-hexadecimal)
add_task(convert-binary-number-in-a-linked-list-to-integer)
add_task(convert-sorted-array-to-binary-search-tree)
add_task(convert-sorted-list-to-binary-search-tree)
add_task(convert-the-temperature)
add_task(copy-list-with-random-pointer)
add_task(count-all-possible-routes)
add_task(count-all-valid-pickup-and-delivery-options)
add_task(count-and-say)
add_task(count-asterisks)
add_task(count-complete-tree-nodes)
add_task(count-days-spent-together)
add_task(count-distinct-numbers-on-board)
add_task(count-good-nodes-in-binary-tree)
add_task(count-negative-numbers-in-a-sorted-matrix)
add_task(count-odd-numbers-in-an-interval-range)
add_task(count-pairs-of-similar-strings)
add_task(count-pairs-whose-sum-is-less-than-target)
add_task(count-prefixes-of-a-given-string)
add_task(count-sub-islands)
add_task(count-subarrays-with-fixed-bounds)
add_task(count-subtrees-with-max-distance-between-cities)
add_task(count-symmetric-integers)
add_task(count-the-digits-that-divide-a-number)
add_task(count-the-number-of-vowel-strings-in-range)
add_task(count-unreachable-pairs-of-nodes-in-an-undirected-graph)
add_task(count-ways-to-build-good-strings)
add_task(counting-bits)
Expand All @@ -153,6 +165,7 @@ add_task(decode-ways)
add_task(decoded-string-at-index)
add_task(decrypt-string-from-alphabet-to-integer-mapping)
add_task(delete-and-earn)
add_task(delete-greatest-value-in-each-row)
add_task(delete-node-in-a-bst)
add_task(delete-node-in-a-linked-list)
add_task(delete-operation-for-two-strings)
Expand All @@ -174,6 +187,7 @@ add_task(detonate-the-maximum-bombs)
add_task(diameter-of-binary-tree)
add_task(difference-between-element-sum-and-digit-sum-of-an-array)
add_task(distinct-subsequences)
add_task(distribute-money-to-maximum-children)
add_task(divisible-and-non-divisible-sums-difference)
add_task(domino-and-tromino-tiling)
add_task(dota2-senate)
Expand All @@ -194,6 +208,7 @@ add_task(find-a-peak-element-ii)
add_task(find-all-anagrams-in-a-string)
add_task(find-all-lonely-numbers-in-the-array)
add_task(find-all-numbers-disappeared-in-an-array)
add_task(find-closest-number-to-zero)
add_task(find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree)
add_task(find-duplicate-subtrees)
add_task(find-eventual-safe-states)
Expand All @@ -214,21 +229,28 @@ add_task(find-resultant-array-after-removing-anagrams)
add_task(find-right-interval)
add_task(find-smallest-letter-greater-than-target)
add_task(find-subarrays-with-equal-sum)
add_task(find-the-array-concatenation-value)
add_task(find-the-difference)
add_task(find-the-difference-of-two-arrays)
add_task(find-the-distance-value-between-two-arrays)
add_task(find-the-distinct-difference-array)
add_task(find-the-divisibility-array-of-a-string)
add_task(find-the-duplicate-number)
add_task(find-the-highest-altitude)
add_task(find-the-index-of-the-first-occurrence-in-a-string)
add_task(find-the-k-beauty-of-a-number)
add_task(find-the-longest-balanced-substring-of-a-binary-string)
add_task(find-the-longest-valid-obstacle-course-at-each-position)
add_task(find-the-losers-of-the-circular-game)
add_task(find-the-maximum-achievable-number)
add_task(find-the-maximum-divisibility-score)
add_task(find-the-maximum-number-of-marked-indices)
add_task(find-the-minimum-and-maximum-number-of-nodes-between-critical-points)
add_task(find-the-pivot-integer)
add_task(find-the-smallest-divisor-given-a-threshold)
add_task(find-the-student-that-will-replace-the-chalk)
add_task(find-the-town-judge)
add_task(find-the-width-of-columns-of-a-grid)
add_task(find-the-winner-of-the-circular-game)
add_task(first-bad-version)
add_task(first-letter-to-appear-twice)
Expand All @@ -238,6 +260,7 @@ add_task(fizz-buzz)
add_task(flatten-binary-tree-to-linked-list)
add_task(flatten-nested-list-iterator)
add_task(flood-fill)
add_task(form-smallest-number-from-two-digit-arrays)
add_task(frequency-of-the-most-frequent-element)
add_task(frog-jump)
add_task(furthest-point-from-origin)
Expand Down Expand Up @@ -285,6 +308,7 @@ add_task(jump-game-ii)
add_task(jump-game-iii)
add_task(jump-game-iv)
add_task(k-closest-points-to-origin)
add_task(k-items-with-the-maximum-sum)
add_task(k-radius-subarray-averages)
add_task(keyboard-row)
add_task(keys-and-rooms)
Expand All @@ -298,6 +322,7 @@ add_task(kth-smallest-element-in-a-bst)
add_task(largest-3-same-digit-number-in-string)
add_task(largest-color-value-in-a-directed-graph)
add_task(largest-local-values-in-a-matrix)
add_task(largest-number-after-digit-swaps-by-parity)
add_task(largest-perimeter-triangle)
add_task(largest-positive-integer-that-exists-with-its-negative)
add_task(largest-rectangle-in-histogram)
Expand Down Expand Up @@ -362,8 +387,11 @@ add_task(maximal-square)
add_task(maximize-score-after-n-operations)
add_task(maximize-the-confusion-of-an-exam)
add_task(maximum-average-subarray-i)
add_task(maximum-count-of-positive-integer-and-negative-integer)
add_task(maximum-depth-of-binary-tree)
add_task(maximum-difference-by-remapping-a-digit)
add_task(maximum-distance-between-a-pair-of-values)
add_task(maximum-enemy-forts-that-can-be-captured)
add_task(maximum-frequency-stack)
add_task(maximum-length-of-pair-chain)
add_task(maximum-length-of-subarray-with-positive-product)
Expand All @@ -383,8 +411,10 @@ add_task(maximum-side-length-of-a-square-with-sum-less-than-or-equal-to-threshol
add_task(maximum-subarray)
add_task(maximum-subsequence-score)
add_task(maximum-sum-circular-subarray)
add_task(maximum-sum-with-exactly-k-elements)
add_task(maximum-twin-sum-of-a-linked-list)
add_task(maximum-value-at-a-given-index-in-a-bounded-array)
add_task(maximum-value-of-a-string-in-an-array)
add_task(maximum-value-of-an-ordered-triplet-i)
add_task(maximum-value-of-k-coins-from-piles)
add_task(maximum-width-of-binary-tree)
Expand All @@ -394,6 +424,7 @@ add_task(merge-k-sorted-lists)
add_task(merge-similar-items)
add_task(merge-sorted-array)
add_task(merge-strings-alternately)
add_task(merge-two-2d-arrays-by-summing-values)
add_task(merge-two-binary-trees)
add_task(merge-two-sorted-lists)
add_task(middle-of-the-linked-list)
Expand All @@ -409,9 +440,11 @@ add_task(minimum-absolute-difference-in-bst)
add_task(minimum-absolute-sum-difference)
add_task(minimum-amount-of-time-to-fill-cups)
add_task(minimum-ascii-delete-sum-for-two-strings)
add_task(minimum-common-value)
add_task(minimum-cost-for-tickets)
add_task(minimum-cost-to-cut-a-stick)
add_task(minimum-cost-to-make-array-equal)
add_task(minimum-cuts-to-divide-a-circle)
add_task(minimum-deletions-to-make-character-frequencies-unique)
add_task(minimum-depth-of-binary-tree)
add_task(minimum-distance-between-bst-nodes)
Expand Down Expand Up @@ -476,8 +509,10 @@ add_task(number-of-beautiful-pairs)
add_task(number-of-closed-islands)
add_task(number-of-common-factors)
add_task(number-of-digit-one)
add_task(number-of-distinct-averages)
add_task(number-of-employees-who-met-the-target)
add_task(number-of-enclaves)
add_task(number-of-even-and-odd-bits)
add_task(number-of-flowers-in-full-bloom)
add_task(number-of-good-pairs)
add_task(number-of-increasing-paths-in-a-grid)
Expand All @@ -488,8 +523,10 @@ add_task(number-of-operations-to-make-network-connected)
add_task(number-of-provinces)
add_task(number-of-recent-calls)
add_task(number-of-segments-in-a-string)
add_task(number-of-senior-citizens)
add_task(number-of-submatrices-that-sum-to-target)
add_task(number-of-subsequences-that-satisfy-the-given-sum-condition)
add_task(number-of-unequal-triplets-in-array)
add_task(number-of-valid-clock-times)
add_task(number-of-visible-people-in-a-queue)
add_task(number-of-ways-of-cutting-a-pizza)
Expand All @@ -509,11 +546,14 @@ add_task(painting-the-walls)
add_task(palindrome-linked-list)
add_task(palindrome-number)
add_task(palindrome-partitioning)
add_task(parallel-courses-ii)
add_task(parallel-courses-iii)
add_task(partition-equal-subset-sum)
add_task(partition-labels)
add_task(partition-list)
add_task(pascals-triangle)
add_task(pascals-triangle-ii)
add_task(pass-the-pillow)
add_task(path-sum)
add_task(path-sum-ii)
add_task(path-sum-iii)
Expand All @@ -536,6 +576,7 @@ add_task(power-of-three)
add_task(power-of-two)
add_task(powx-n)
add_task(predict-the-winner)
add_task(prime-in-diagonal)
add_task(product-of-array-except-self)
add_task(product-of-the-last-k-numbers)
add_task(profitable-schemes)
Expand Down Expand Up @@ -585,10 +626,12 @@ add_task(reverse-words-in-a-string)
add_task(reverse-words-in-a-string-iii)
add_task(richest-customer-wealth)
add_task(roman-to-integer)
add_task(root-equals-sum-of-children)
add_task(rotate-array)
add_task(rotate-image)
add_task(rotate-list)
add_task(rotting-oranges)
add_task(row-with-maximum-ones)
add_task(running-sum-of-1d-array)
add_task(same-tree)
add_task(scramble-string)
Expand All @@ -602,10 +645,12 @@ add_task(search-suggestions-system)
add_task(seat-reservation-manager)
add_task(sell-diminishing-valued-colored-balls)
add_task(semi-ordered-permutation)
add_task(separate-the-digits-in-an-array)
add_task(sequentially-ordinal-rank-tracker)
add_task(serialize-and-deserialize-binary-tree)
add_task(set-matrix-zeroes)
add_task(shortest-bridge)
add_task(shortest-distance-to-target-string-in-a-circular-array)
add_task(shortest-impossible-sequence-of-rolls)
add_task(shortest-path-in-binary-matrix)
add_task(shortest-path-to-get-all-keys)
Expand Down Expand Up @@ -645,6 +690,7 @@ add_task(spiral-matrix)
add_task(spiral-matrix-ii)
add_task(split-linked-list-in-parts)
add_task(split-strings-by-separator)
add_task(split-with-minimum-sum)
add_task(sqrtx)
add_task(squares-of-a-sorted-array)
add_task(stone-game-ii)
Expand All @@ -663,6 +709,7 @@ add_task(subtract-the-product-and-sum-of-digits-of-an-integer)
add_task(subtree-of-another-tree)
add_task(successful-pairs-of-spells-and-potions)
add_task(sudoku-solver)
add_task(sum-multiples)
add_task(sum-of-all-odd-length-subarrays)
add_task(sum-of-left-leaves)
add_task(sum-of-mutated-array-closest-to-target)
Expand All @@ -675,6 +722,7 @@ add_task(surrounded-regions)
add_task(swap-nodes-in-pairs)
add_task(swapping-nodes-in-a-linked-list)
add_task(symmetric-tree)
add_task(take-gifts-from-the-richest-pile)
add_task(tallest-billboard)
add_task(task-scheduler)
add_task(text-justification)
Expand Down
1 change: 1 addition & 0 deletions solutions/add-two-integers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_catch(test_add_two_integers test.cpp)
6 changes: 6 additions & 0 deletions solutions/add-two-integers/solution.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

class Solution {
public:
static int sum(int num1, int num2) { return num1 + num2; }
};
29 changes: 29 additions & 0 deletions solutions/add-two-integers/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <catch.hpp>

#include <solution.hpp>

TEST_CASE("Simple") {
struct TestCase {
int num1;
int num2;
int expected;
};

std::vector<TestCase> test_cases{
{
.num1 = 12,
.num2 = 5,
.expected = 17,
},
{
.num1 = -10,
.num2 = 4,
.expected = -6,
},
};

for (const auto &[num1, num2, expected] : test_cases) {
const auto actual = Solution::sum(num1, num2);
REQUIRE(expected == actual);
}
}
1 change: 1 addition & 0 deletions solutions/alternating-digit-sum/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_catch(test_alternating_digit_sum test.cpp)
13 changes: 13 additions & 0 deletions solutions/alternating-digit-sum/solution.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

class Solution {
public:
static int alternateDigitSum(int n) {
int sum = 0, sign = 1;
for (auto i = n; i; i /= 10) {
sign *= -1;
sum += sign * i % 10;
}
return sign * sum;
}
};
30 changes: 30 additions & 0 deletions solutions/alternating-digit-sum/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <catch.hpp>

#include <solution.hpp>

TEST_CASE("Simple") {
struct TestCase {
int n;
int expected;
};

std::vector<TestCase> test_cases{
{
.n = 521,
.expected = 4,
},
{
.n = 111,
.expected = 1,
},
{
.n = 886996,
.expected = 0,
},
};

for (const auto &[n, expected] : test_cases) {
const auto actual = Solution::alternateDigitSum(n);
REQUIRE(expected == actual);
}
}
1 change: 1 addition & 0 deletions solutions/apply-operations-to-an-array/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_catch(test_apply_operations_to_an_array test.cpp)
Loading
Loading