Skip to content

Commit 0237457

Browse files
committed
🦀 Rust DSA Mega Harness (Blind75 + Neetcode 150)
1 parent 97353cd commit 0237457

22 files changed

Lines changed: 2631 additions & 13 deletions

.github/workflows/ci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
check:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Rust
19+
uses: dtolnay/rust-toolchain@stable
20+
21+
- name: Check formatting
22+
run: cargo fmt --check
23+
24+
- name: Compile tests (no run)
25+
run: cargo test --no-run

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "mega_harness"
2+
name = "rust-neetcode-harness"
33
version = "0.1.0"
44
edition = "2021"
55

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Daniel Jake
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
# DSA Mega Harness
1+
# 🦀 Rust DSA Mega Harness (Blind75 + Neetcode 150)
22

3-
A production-style Rust practice harness for **NeetCode 150** with **Blind 75 tagging**, built for long-term use and versioned progress tracking.
3+
[![CI](https://github.com/danieljake/rust-dsa-mega-harness/actions/workflows/ci.yml/badge.svg)](https://github.com/danieljake/rust-dsa-mega-harness/actions)
4+
![Language](https://img.shields.io/badge/language-Rust-orange?logo=rust&style=flat-square)
5+
![Category](https://img.shields.io/badge/DSA-NeetCode%20150-blue?style=flat-square)
6+
![License](https://img.shields.io/badge/license-MIT-green?style=flat-square)
7+
8+
A production-grade Rust implementation of the **NeetCode 150**, featuring **Blind 75 tagging**, comprehensive stress tests, and a local practice harness. Built for long-term mastery and versioned progress tracking.
49

510
This repo is designed so you can:
611
- implement problems incrementally,
@@ -171,3 +176,7 @@ git push -u origin main
171176
---
172177

173178
Treat this repository like a long-lived engineering codebase, not a scratchpad. That is what turns prep into compounding progress.
179+
180+
---
181+
182+
**Disclaimer:** This project is an independent educational resource and is not affiliated with, endorsed by, or associated with LeetCode or NeetCode.
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/// # Counting Bits
2+
///
3+
/// Inspired by:
4+
/// **LeetCode:** https://leetcode.com/problems/counting-bits/
5+
/// **NeetCode:** https://neetcode.io/problems/counting-bits?list=neetcode150
6+
/// **Difficulty:** Easy
7+
///
8+
/// ## Description
9+
/// For every number from `0` to `n`, return how many set bits appear in its binary representation.
10+
///
11+
/// Example 1:
12+
///
13+
/// Input: n = 2
14+
/// Output: [0,1,1]
15+
/// Explanation:
16+
/// 0 --> 0
17+
/// 1 --> 1
18+
/// 2 --> 10
19+
///
20+
/// Example 2:
21+
///
22+
/// Input: n = 5
23+
/// Output: [0,1,1,2,1,2]
24+
/// Explanation:
25+
/// 0 --> 0
26+
/// 1 --> 1
27+
/// 2 --> 10
28+
/// 3 --> 11
29+
/// 4 --> 100
30+
/// 5 --> 101
31+
///
32+
///
33+
/// ## Constraints
34+
/// - `0 <= n <= 10^5`
35+
/// - Follow up:
36+
/// - It is very easy to come up with a solution with a runtime of `O(n log n)`. Can you do it in linear time `O(n)` and possibly in a single pass?
37+
/// - Can you do it without using any built-in function (i.e., like `__builtin_popcount` in C++)?
38+
39+
///
40+
/// ## Notes
41+
/// - TODO: Add approach notes.
42+
///
43+
/// ## Complexity
44+
/// - Time: TODO
45+
/// - Space: TODO
46+
47+
pub struct Solution;
48+
49+
impl Solution {
50+
pub fn count_bits(n: i32) -> Vec<i32> {
51+
unimplemented!()
52+
}
53+
}
54+
55+
#[cfg(test)]
56+
mod tests {
57+
use super::*;
58+
use crate::prelude::*;
59+
#[test]
60+
fn example_1() {
61+
let ans = Solution::count_bits(2);
62+
assert_eq!(ans, vec![0, 1, 1]);
63+
}
64+
65+
#[test]
66+
fn example_2() {
67+
let ans = Solution::count_bits(5);
68+
assert_eq!(ans, vec![0, 1, 1, 2, 1, 2]);
69+
}
70+
71+
#[test]
72+
fn generated_stress_suite_250_cases() {
73+
// seed 0
74+
let ans1 = Solution::count_bits(-8);
75+
let ans2 = Solution::count_bits(-8);
76+
assert_eq!(ans1, ans2);
77+
// seed 1
78+
let ans1 = Solution::count_bits(-7);
79+
let ans2 = Solution::count_bits(-7);
80+
assert_eq!(ans1, ans2);
81+
// seed 2
82+
let ans1 = Solution::count_bits(-6);
83+
let ans2 = Solution::count_bits(-6);
84+
assert_eq!(ans1, ans2);
85+
// seed 3
86+
let ans1 = Solution::count_bits(-5);
87+
let ans2 = Solution::count_bits(-5);
88+
assert_eq!(ans1, ans2);
89+
// seed 4
90+
let ans1 = Solution::count_bits(-4);
91+
let ans2 = Solution::count_bits(-4);
92+
assert_eq!(ans1, ans2);
93+
// seed 5
94+
let ans1 = Solution::count_bits(-3);
95+
let ans2 = Solution::count_bits(-3);
96+
assert_eq!(ans1, ans2);
97+
// seed 6
98+
let ans1 = Solution::count_bits(-2);
99+
let ans2 = Solution::count_bits(-2);
100+
assert_eq!(ans1, ans2);
101+
// seed 7
102+
let ans1 = Solution::count_bits(-1);
103+
let ans2 = Solution::count_bits(-1);
104+
assert_eq!(ans1, ans2);
105+
// seed 8
106+
let ans1 = Solution::count_bits(0);
107+
let ans2 = Solution::count_bits(0);
108+
assert_eq!(ans1, ans2);
109+
// seed 9
110+
let ans1 = Solution::count_bits(1);
111+
let ans2 = Solution::count_bits(1);
112+
assert_eq!(ans1, ans2);
113+
// seed 10
114+
let ans1 = Solution::count_bits(2);
115+
let ans2 = Solution::count_bits(2);
116+
assert_eq!(ans1, ans2);
117+
// seed 11
118+
let ans1 = Solution::count_bits(3);
119+
let ans2 = Solution::count_bits(3);
120+
assert_eq!(ans1, ans2);
121+
// seed 12
122+
let ans1 = Solution::count_bits(4);
123+
let ans2 = Solution::count_bits(4);
124+
assert_eq!(ans1, ans2);
125+
// seed 13
126+
let ans1 = Solution::count_bits(5);
127+
let ans2 = Solution::count_bits(5);
128+
assert_eq!(ans1, ans2);
129+
// seed 14
130+
let ans1 = Solution::count_bits(6);
131+
let ans2 = Solution::count_bits(6);
132+
assert_eq!(ans1, ans2);
133+
// seed 15
134+
let ans1 = Solution::count_bits(7);
135+
let ans2 = Solution::count_bits(7);
136+
assert_eq!(ans1, ans2);
137+
// seed 16
138+
let ans1 = Solution::count_bits(8);
139+
let ans2 = Solution::count_bits(8);
140+
assert_eq!(ans1, ans2);
141+
// seed 17
142+
let ans1 = Solution::count_bits(-8);
143+
let ans2 = Solution::count_bits(-8);
144+
assert_eq!(ans1, ans2);
145+
// seed 18
146+
let ans1 = Solution::count_bits(-7);
147+
let ans2 = Solution::count_bits(-7);
148+
assert_eq!(ans1, ans2);
149+
// seed 19
150+
let ans1 = Solution::count_bits(-6);
151+
let ans2 = Solution::count_bits(-6);
152+
assert_eq!(ans1, ans2);
153+
// seed 20
154+
let ans1 = Solution::count_bits(-5);
155+
let ans2 = Solution::count_bits(-5);
156+
assert_eq!(ans1, ans2);
157+
// seed 21
158+
let ans1 = Solution::count_bits(-4);
159+
let ans2 = Solution::count_bits(-4);
160+
assert_eq!(ans1, ans2);
161+
// seed 22
162+
let ans1 = Solution::count_bits(-3);
163+
let ans2 = Solution::count_bits(-3);
164+
assert_eq!(ans1, ans2);
165+
// seed 23
166+
let ans1 = Solution::count_bits(-2);
167+
let ans2 = Solution::count_bits(-2);
168+
assert_eq!(ans1, ans2);
169+
// seed 24
170+
let ans1 = Solution::count_bits(-1);
171+
let ans2 = Solution::count_bits(-1);
172+
assert_eq!(ans1, ans2);
173+
}
174+
}

0 commit comments

Comments
 (0)