From f482f347181373e77a0cc66c7f0757cc2a037249 Mon Sep 17 00:00:00 2001 From: Atharv R Tingane Date: Sat, 4 Oct 2025 20:29:26 +0530 Subject: [PATCH 1/3] Sloved problem in c++ --- Number of People Aware of a Secret.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Number of People Aware of a Secret.cpp diff --git a/Number of People Aware of a Secret.cpp b/Number of People Aware of a Secret.cpp new file mode 100644 index 0000000..6c9a52d --- /dev/null +++ b/Number of People Aware of a Secret.cpp @@ -0,0 +1,19 @@ +class Solution { +public: + int peopleAwareOfSecret(int n, int delay, int forget) { + vector dp(n + 1, 0); + dp[1] = 1; + long long share = 0, MOD = 1000000007; + for (int t = 2; t <= n; t++) { + if (t - delay > 0) + share = (share + dp[t - delay] + MOD) % MOD; + if (t - forget > 0) + share = (share - dp[t - forget] + MOD) % MOD; + dp[t] = share; + } + long long know = 0; + for (int i = n - forget + 1; i <= n; i++) + know = (know + dp[i]) % MOD; + return (int)know; + } +}; From aaf142bc8f8c52759f503321611ea5f15a31865f Mon Sep 17 00:00:00 2001 From: Atharv R Tingane Date: Sat, 4 Oct 2025 23:10:46 +0530 Subject: [PATCH 2/3] Modified Sloved problem in c+ --- 36. Valid Sudoku | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 36. Valid Sudoku diff --git a/36. Valid Sudoku b/36. Valid Sudoku new file mode 100644 index 0000000..afe2563 --- /dev/null +++ b/36. Valid Sudoku @@ -0,0 +1,40 @@ +// Approach + +// We use hash sets (or boolean arrays) to track seen numbers: +// For each cell (i, j), if it contains a number x, we check: +// If x is already seen in row i. +// If x is already seen in column j. +// If x is already seen in its 3×3 sub-box indexed by (i/3, j/3). +// If any duplicate is found, return false. +// Otherwise, the board is valid. + +// Intuition + +// The Sudoku grid is only 9×9, so we can directly check all constraints efficiently. +// We leverage the mathematical mapping of sub-box index as boxIndex = (i / 3) * 3 + (j / 3). + +// Complexity + +// Time Complexity: O(81) → O(1) Constant time. +// Space Complexity: O(81) → O(1) Constant space. + +/* code + vector> rows(9), cols(9), boxes(9); + + for (int i = 0; i < 9; i++) { + for (int j = 0; j < 9; j++) { + char c = board[i][j]; + if (c == '.') continue; + + int boxIndex = (i / 3) * 3 + (j / 3); + + if (rows[i].count(c) || cols[j].count(c) || boxes[boxIndex].count(c)) + return false; + + rows[i].insert(c); + cols[j].insert(c); + boxes[boxIndex].insert(c); + } + } + return true; +*/ \ No newline at end of file From ab7be6eec23d5ed010a5619a8d02a04cb421534c Mon Sep 17 00:00:00 2001 From: Atharv R Tingane Date: Sat, 4 Oct 2025 23:49:51 +0530 Subject: [PATCH 3/3] Modified Sloved problem in c+ --- 36. Valid Sudoku | 40 ---------------------------------------- 36. Valid Sudoku.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 40 deletions(-) delete mode 100644 36. Valid Sudoku create mode 100644 36. Valid Sudoku.cpp diff --git a/36. Valid Sudoku b/36. Valid Sudoku deleted file mode 100644 index afe2563..0000000 --- a/36. Valid Sudoku +++ /dev/null @@ -1,40 +0,0 @@ -// Approach - -// We use hash sets (or boolean arrays) to track seen numbers: -// For each cell (i, j), if it contains a number x, we check: -// If x is already seen in row i. -// If x is already seen in column j. -// If x is already seen in its 3×3 sub-box indexed by (i/3, j/3). -// If any duplicate is found, return false. -// Otherwise, the board is valid. - -// Intuition - -// The Sudoku grid is only 9×9, so we can directly check all constraints efficiently. -// We leverage the mathematical mapping of sub-box index as boxIndex = (i / 3) * 3 + (j / 3). - -// Complexity - -// Time Complexity: O(81) → O(1) Constant time. -// Space Complexity: O(81) → O(1) Constant space. - -/* code - vector> rows(9), cols(9), boxes(9); - - for (int i = 0; i < 9; i++) { - for (int j = 0; j < 9; j++) { - char c = board[i][j]; - if (c == '.') continue; - - int boxIndex = (i / 3) * 3 + (j / 3); - - if (rows[i].count(c) || cols[j].count(c) || boxes[boxIndex].count(c)) - return false; - - rows[i].insert(c); - cols[j].insert(c); - boxes[boxIndex].insert(c); - } - } - return true; -*/ \ No newline at end of file diff --git a/36. Valid Sudoku.cpp b/36. Valid Sudoku.cpp new file mode 100644 index 0000000..b22cfbb --- /dev/null +++ b/36. Valid Sudoku.cpp @@ -0,0 +1,28 @@ +class Solution { +public: + bool isValidSudoku(vector>& board) { + bitset<9> Col[9]; + bitset<9> Row[9]; + bitset<9> Block[9]; + + for(int i = 0; i < 9; i++){ + for(int j = 0; j < 9; j++){ + char c = board[i][j]; + if (c == '.') continue; + int x = (c - '0') % 9; + + if (Row[i][x]) return 0; + Row[i][x] = 1; + + if (Col[j][x]) return 0; + Col[j][x] = 1; + + int bidx = (i / 3) * 3 + j / 3; + + if (Block[bidx][x]) return 0; + Block[bidx][x] = 1; + } + } + return 1; + } +}; \ No newline at end of file