Skip to content

Sri Hari: Batch-9/Added articles/Neetcode All #4689

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

Merged
merged 5 commits into from
Aug 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
88 changes: 88 additions & 0 deletions articles/arranging-coins.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ class Solution {
}
```

```csharp
public class Solution {
public int ArrangeCoins(int n) {
int row = 0;
while (n - row > 0) {
row++;
n -= row;
}
return row;
}
}
```

::tabs-end

### Time & Space Complexity
Expand Down Expand Up @@ -155,6 +168,29 @@ class Solution {
}
```

```csharp
public class Solution {
public int ArrangeCoins(int n) {
int l = 1, r = n;
int res = 0;

while (l <= r) {
int mid = l + (r - l) / 2;
long coins = (long)mid * (mid + 1) / 2;

if (coins > n) {
r = mid - 1;
} else {
res = Math.Max(res, mid);
l = mid + 1;
}
}

return res;
}
}
```

::tabs-end

### Time & Space Complexity
Expand Down Expand Up @@ -259,6 +295,30 @@ class Solution {
}
```

```csharp
public class Solution {
public int ArrangeCoins(int n) {
if (n <= 3) {
return n == 1 ? 1 : n - 1;
}

int l = 1, r = (n / 2) + 1;
while (l < r) {
int mid = (l + r) / 2;
long coins = (long)mid * (mid + 1) / 2;

if (coins <= n) {
l = mid + 1;
} else {
r = mid;
}
}

return l - 1;
}
}
```

::tabs-end

### Time & Space Complexity
Expand Down Expand Up @@ -345,6 +405,26 @@ class Solution {
}
```

```csharp
public class Solution {
public int ArrangeCoins(int n) {
int mask = 1 << 15;
int rows = 0;

while (mask > 0) {
rows |= mask;
long coins = (long)rows * (rows + 1) / 2;
if (coins > n) {
rows ^= mask;
}
mask >>= 1;
}

return rows;
}
}
```

::tabs-end

### Time & Space Complexity
Expand Down Expand Up @@ -393,6 +473,14 @@ class Solution {
}
```

```csharp
public class Solution {
public int ArrangeCoins(int n) {
return (int)(Math.Sqrt(2L * n + 0.25) - 0.5);
}
}
```

::tabs-end

### Time & Space Complexity
Expand Down
61 changes: 61 additions & 0 deletions articles/buy-two-chocolates.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public:

```javascript
class Solution {
/**
* @param {number[]} prices
* @param {number} money
* @return {number}
*/
buyChoco(prices, money) {
let res = -1;
for (let i = 0; i < prices.length; i++) {
Expand All @@ -62,6 +67,22 @@ class Solution {
}
```

```csharp
public class Solution {
public int BuyChoco(int[] prices, int money) {
int res = -1;
for (int i = 0; i < prices.Length; i++) {
for (int j = i + 1; j < prices.Length; j++) {
if (prices[i] + prices[j] <= money) {
res = Math.Max(res, money - prices[i] - prices[j]);
}
}
}
return res == -1 ? money : res;
}
}
```

::tabs-end

### Time & Space Complexity
Expand Down Expand Up @@ -106,6 +127,11 @@ public:

```javascript
class Solution {
/**
* @param {number[]} prices
* @param {number} money
* @return {number}
*/
buyChoco(prices, money) {
prices.sort((a, b) => a - b);
let buy = prices[0] + prices[1];
Expand All @@ -114,6 +140,16 @@ class Solution {
}
```

```csharp
public class Solution {
public int BuyChoco(int[] prices, int money) {
Array.Sort(prices);
int buy = prices[0] + prices[1];
return buy > money ? money : money - buy;
}
}
```

::tabs-end

### Time & Space Complexity
Expand Down Expand Up @@ -185,6 +221,11 @@ public:

```javascript
class Solution {
/**
* @param {number[]} prices
* @param {number} money
* @return {number}
*/
buyChoco(prices, money) {
let min1 = Infinity, min2 = Infinity;

Expand All @@ -203,6 +244,26 @@ class Solution {
}
```

```csharp
public class Solution {
public int BuyChoco(int[] prices, int money) {
int min1 = int.MaxValue, min2 = int.MaxValue;

foreach (int p in prices) {
if (p < min1) {
min2 = min1;
min1 = p;
} else if (p < min2) {
min2 = p;
}
}

int leftover = money - min1 - min2;
return leftover >= 0 ? leftover : money;
}
}
```

::tabs-end

### Time & Space Complexity
Expand Down
35 changes: 35 additions & 0 deletions articles/count-odd-numbers-in-an-interval-range.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ class Solution {
}
```

```csharp
public class Solution {
public int CountOdds(int low, int high) {
int odd = 0;
for (int num = low; num <= high; num++) {
if ((num & 1) == 1) {
odd++;
}
}
return odd;
}
}
```

::tabs-end

### Time & Space Complexity
Expand Down Expand Up @@ -130,6 +144,19 @@ class Solution {
}
```

```csharp
public class Solution {
public int CountOdds(int low, int high) {
int length = high - low + 1;
int count = length / 2;
if ((length % 2 == 1) && (low % 2 == 1)) {
count++;
}
return count;
}
}
```

::tabs-end

### Time & Space Complexity
Expand Down Expand Up @@ -179,6 +206,14 @@ class Solution {
}
```

```csharp
public class Solution {
public int CountOdds(int low, int high) {
return ((high + 1) >> 1) - (low >> 1);
}
}
```

::tabs-end

### Time & Space Complexity
Expand Down
Loading
Loading