From 96d2e24a81f101fad143acc0740949240b6a21cf Mon Sep 17 00:00:00 2001 From: Rajeev Singh Jadon Date: Mon, 18 Sep 2023 16:13:54 +0530 Subject: [PATCH] Organising Files... --- .../week 2/{ => solutions}/solution_1.cpp | 0 .../week 2/{ => solutions}/solution_2.cpp | 0 .../week 2/{ => solutions}/solution_3.cpp | 0 .../week 2/{ => solutions}/solution_4.cpp | 0 .../week 2/{ => solutions}/solution_5.cpp | 0 .../week 2/{ => solutions}/solution_6.cpp | 0 .../week 2/{ => solutions}/solution_7.cpp | 0 .../week 2/{ => solutions}/solution_8.cpp | 0 .../week 3/{ => solutions}/solution_1.cpp | 0 .../week 3/{ => solutions}/solution_2.cpp | 0 .../week 3/{ => solutions}/solution_3.cpp | 0 .../week 3/{ => solutions}/solution_4.cpp | 0 .../week 3/{ => solutions}/solution_5.cpp | 0 .../week 3/{ => solutions}/solution_6.cpp | 0 .../week 3/{ => solutions}/solution_7.cpp | 176 +++++++++--------- .../week 3/{ => solutions}/solution_8.cpp | 0 16 files changed, 88 insertions(+), 88 deletions(-) rename Questions/week 2/{ => solutions}/solution_1.cpp (100%) rename Questions/week 2/{ => solutions}/solution_2.cpp (100%) rename Questions/week 2/{ => solutions}/solution_3.cpp (100%) rename Questions/week 2/{ => solutions}/solution_4.cpp (100%) rename Questions/week 2/{ => solutions}/solution_5.cpp (100%) rename Questions/week 2/{ => solutions}/solution_6.cpp (100%) rename Questions/week 2/{ => solutions}/solution_7.cpp (100%) rename Questions/week 2/{ => solutions}/solution_8.cpp (100%) rename Questions/week 3/{ => solutions}/solution_1.cpp (100%) rename Questions/week 3/{ => solutions}/solution_2.cpp (100%) rename Questions/week 3/{ => solutions}/solution_3.cpp (100%) rename Questions/week 3/{ => solutions}/solution_4.cpp (100%) rename Questions/week 3/{ => solutions}/solution_5.cpp (100%) rename Questions/week 3/{ => solutions}/solution_6.cpp (100%) rename Questions/week 3/{ => solutions}/solution_7.cpp (93%) rename Questions/week 3/{ => solutions}/solution_8.cpp (100%) diff --git a/Questions/week 2/solution_1.cpp b/Questions/week 2/solutions/solution_1.cpp similarity index 100% rename from Questions/week 2/solution_1.cpp rename to Questions/week 2/solutions/solution_1.cpp diff --git a/Questions/week 2/solution_2.cpp b/Questions/week 2/solutions/solution_2.cpp similarity index 100% rename from Questions/week 2/solution_2.cpp rename to Questions/week 2/solutions/solution_2.cpp diff --git a/Questions/week 2/solution_3.cpp b/Questions/week 2/solutions/solution_3.cpp similarity index 100% rename from Questions/week 2/solution_3.cpp rename to Questions/week 2/solutions/solution_3.cpp diff --git a/Questions/week 2/solution_4.cpp b/Questions/week 2/solutions/solution_4.cpp similarity index 100% rename from Questions/week 2/solution_4.cpp rename to Questions/week 2/solutions/solution_4.cpp diff --git a/Questions/week 2/solution_5.cpp b/Questions/week 2/solutions/solution_5.cpp similarity index 100% rename from Questions/week 2/solution_5.cpp rename to Questions/week 2/solutions/solution_5.cpp diff --git a/Questions/week 2/solution_6.cpp b/Questions/week 2/solutions/solution_6.cpp similarity index 100% rename from Questions/week 2/solution_6.cpp rename to Questions/week 2/solutions/solution_6.cpp diff --git a/Questions/week 2/solution_7.cpp b/Questions/week 2/solutions/solution_7.cpp similarity index 100% rename from Questions/week 2/solution_7.cpp rename to Questions/week 2/solutions/solution_7.cpp diff --git a/Questions/week 2/solution_8.cpp b/Questions/week 2/solutions/solution_8.cpp similarity index 100% rename from Questions/week 2/solution_8.cpp rename to Questions/week 2/solutions/solution_8.cpp diff --git a/Questions/week 3/solution_1.cpp b/Questions/week 3/solutions/solution_1.cpp similarity index 100% rename from Questions/week 3/solution_1.cpp rename to Questions/week 3/solutions/solution_1.cpp diff --git a/Questions/week 3/solution_2.cpp b/Questions/week 3/solutions/solution_2.cpp similarity index 100% rename from Questions/week 3/solution_2.cpp rename to Questions/week 3/solutions/solution_2.cpp diff --git a/Questions/week 3/solution_3.cpp b/Questions/week 3/solutions/solution_3.cpp similarity index 100% rename from Questions/week 3/solution_3.cpp rename to Questions/week 3/solutions/solution_3.cpp diff --git a/Questions/week 3/solution_4.cpp b/Questions/week 3/solutions/solution_4.cpp similarity index 100% rename from Questions/week 3/solution_4.cpp rename to Questions/week 3/solutions/solution_4.cpp diff --git a/Questions/week 3/solution_5.cpp b/Questions/week 3/solutions/solution_5.cpp similarity index 100% rename from Questions/week 3/solution_5.cpp rename to Questions/week 3/solutions/solution_5.cpp diff --git a/Questions/week 3/solution_6.cpp b/Questions/week 3/solutions/solution_6.cpp similarity index 100% rename from Questions/week 3/solution_6.cpp rename to Questions/week 3/solutions/solution_6.cpp diff --git a/Questions/week 3/solution_7.cpp b/Questions/week 3/solutions/solution_7.cpp similarity index 93% rename from Questions/week 3/solution_7.cpp rename to Questions/week 3/solutions/solution_7.cpp index 1da08fe..48780a0 100644 --- a/Questions/week 3/solution_7.cpp +++ b/Questions/week 3/solutions/solution_7.cpp @@ -1,88 +1,88 @@ -#include -using namespace std; - -#define pii pair -class Solution { - -public: - int getMinDiff(int arr[], int n, int k) - { - - if (n == 1) - return 0; - - sort(arr, arr + n); - - vector t; - - map m; - - int n_ = 1; - - t.push_back(pii(arr[0] + k, arr[0])); - - t.push_back(pii(arr[0] - k, arr[0])); - - for (int i = 1; i < n; i++) { - - if (arr[i] != arr[i - 1]) { - - t.push_back(pii(arr[i] + k, arr[i])); - - t.push_back(pii(arr[i] - k, arr[i])); - - m[arr[i]] = 0; - - n_++; - } - } - - sort(t.begin(), t.end()); - - int l = 0, r = 0; - - int ans = t[t.size() - 1].first - t[0].first; - - int count = 0; - - while (r < t.size()) { - - while (r < t.size() and count < n_) { - - if (m[t[r].second] == 0) - count++; - - m[t[r].second]++; - - r++; - } - - if (r == t.size() and count < n_) - break; - - ans = min(ans, t[r - 1].first - t[l].first); - - while (l <= r and count >= n_) { - - if (m[t[l].second] == 1) - count--; - - m[t[l].second]--; - - ans = min(ans, t[r - 1].first - t[l].first); - - l++; - } - } - - return ans; - } -}; - -int main() -{ - Solution s; - int k = 5, n = 10; - int arr[n] = { 8, 1, 5, 4, 7, 5, 7, 9, 4, 6 }; - cout << s.getMinDiff(arr, n, k); -} +#include +using namespace std; + +#define pii pair +class Solution { + +public: + int getMinDiff(int arr[], int n, int k) + { + + if (n == 1) + return 0; + + sort(arr, arr + n); + + vector t; + + map m; + + int n_ = 1; + + t.push_back(pii(arr[0] + k, arr[0])); + + t.push_back(pii(arr[0] - k, arr[0])); + + for (int i = 1; i < n; i++) { + + if (arr[i] != arr[i - 1]) { + + t.push_back(pii(arr[i] + k, arr[i])); + + t.push_back(pii(arr[i] - k, arr[i])); + + m[arr[i]] = 0; + + n_++; + } + } + + sort(t.begin(), t.end()); + + int l = 0, r = 0; + + int ans = t[t.size() - 1].first - t[0].first; + + int count = 0; + + while (r < t.size()) { + + while (r < t.size() and count < n_) { + + if (m[t[r].second] == 0) + count++; + + m[t[r].second]++; + + r++; + } + + if (r == t.size() and count < n_) + break; + + ans = min(ans, t[r - 1].first - t[l].first); + + while (l <= r and count >= n_) { + + if (m[t[l].second] == 1) + count--; + + m[t[l].second]--; + + ans = min(ans, t[r - 1].first - t[l].first); + + l++; + } + } + + return ans; + } +}; + +int main() +{ + Solution s; + int k = 5, n = 10; + int arr[n] = { 8, 1, 5, 4, 7, 5, 7, 9, 4, 6 }; + cout << s.getMinDiff(arr, n, k); +} diff --git a/Questions/week 3/solution_8.cpp b/Questions/week 3/solutions/solution_8.cpp similarity index 100% rename from Questions/week 3/solution_8.cpp rename to Questions/week 3/solutions/solution_8.cpp