diff --git a/Domains/CompetitiveProgramming/Programs/C++/AssembleTheTable.cpp b/Domains/CompetitiveProgramming/Programs/C++/AssembleTheTable.cpp new file mode 100644 index 00000000..1334fdf6 --- /dev/null +++ b/Domains/CompetitiveProgramming/Programs/C++/AssembleTheTable.cpp @@ -0,0 +1,70 @@ +/* +Problem: Собери стол (Assemble the table) +Platform: Codeforces +Problem Code: 648B +Difficulty: Easy (800 rated) +Link: https://codeforces.com/problemset/problem/648/B + +Vasya bought a table with n legs. Each leg consists of two parts that connect to each other. Each part can have any positive length, but it is guaranteed that it is possible to compose n legs of the same length from all 2n parts . When composing a leg , any two parts can be connected to each other. Initially, all the table legs are disassembled, and you are given the lengths of the 2n parts in any order. + +Help Vasya assemble all the table legs so that they are all the same length by pairing the given 2n pieces correctly. Each leg must be made of exactly two pieces; using only one piece as a leg is not allowed. + +Input data +The first line contains the number n ( 1 ≤  n  ≤ 1000 ) — the number of legs on the table bought by Vasya. + +The second line contains a sequence of 2 n positive integers a 1 ,  a 2 , ...,  a 2 n ( 1 ≤  a i  ≤ 100 000 ) — the lengths of the parts of the table legs in random order. + +Output data +Print n lines of two integers each—the lengths of the leg pieces that need to be joined together. It is guaranteed that it is always possible to assemble n legs of the same length. If there are multiple answers, you are allowed to print any of them. + +Examples: +Input data +3 +1 3 2 4 5 3 +Output data +1 5 +2 4 +3 3 + +Input data +3 +1 1 1 2 2 2 +Output data +1 2 +2 1 +1 2 + +Approach: +1. Sorted the given array. +2. returned pairs of {ith, (size - i)th}, where i < size/2. + +Time Complexity: O(n log n) +Space Complexity: O(n) + +Contributor: SamaKool +*/ + +#include +#include +#include +#include +using namespace std; + +class Solution +{ +public: + int n; + vector sizes; +}; +int main() +{ + Solution lol; + cin >> lol.n; + lol.sizes.reserve(2*lol.n); + copy_n(istream_iterator(cin), 2*lol.n, back_inserter(lol.sizes)); + sort(lol.sizes.begin(), lol.sizes.end()); + for(int i = 0; i < lol.n; i++){ + cout << lol.sizes[i] << " " << lol.sizes[2*lol.n - i - 1] << endl; + } + return 0; +} \ No newline at end of file diff --git a/Domains/CompetitiveProgramming/Programs/C++/ReverseInteger.cpp b/Domains/CompetitiveProgramming/Programs/C++/ReverseInteger.cpp new file mode 100644 index 00000000..05a97ca9 --- /dev/null +++ b/Domains/CompetitiveProgramming/Programs/C++/ReverseInteger.cpp @@ -0,0 +1,60 @@ +/* +Probelm: Reverse Integer +Platform: Leetcode +problem Code: 7 +Difficulty: Medium +Link: https://leetcode.com/problems/reverse-integer/description/ + +Problem Statement: +Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0. + +Assume the environment does not allow you to store 64-bit integers (signed or unsigned). + + + +Example 1: + +Input: x = 123 +Output: 321 +Example 2: + +Input: x = -123 +Output: -321 +Example 3: + +Input: x = 120 +Output: 21 + + +Constraints: + +-231 <= x <= 231 - 1 + +Approach: +1. extracted the least significant digit(one's place) +2. added it as the most significant digit +3. looped this till completion + +Time Complexity: O(n) +Space Complexity: O(1) + +Contributor: SamaKool +*/ + +class Solution { +public: + int reverse(int x) { + long revn = 0; + + while(x != 0) { + int lastd = x % 10; + revn = revn * 10 + lastd; + x /= 10; + } + if (revn > INT_MAX || revn < INT_MIN) { + return 0; + } + + return revn; + } +}; \ No newline at end of file diff --git a/Domains/CompetitiveProgramming/Programs/C++/SortColors.cpp b/Domains/CompetitiveProgramming/Programs/C++/SortColors.cpp new file mode 100644 index 00000000..8efad4e2 --- /dev/null +++ b/Domains/CompetitiveProgramming/Programs/C++/SortColors.cpp @@ -0,0 +1,61 @@ +/* +Probelm: Sort Colors +Platform: Leetcode +problem Code: 75 +Difficulty: Medium +Link: https://leetcode.com/problems/sort-colors/description/ + +Problem Statement: +Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue. + +We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively. + +You must solve this problem without using the library's sort function. + + + +Example 1: + +Input: nums = [2,0,2,1,1,0] +Output: [0,0,1,1,2,2] +Example 2: + +Input: nums = [2,0,1] +Output: [0,1,2] + + +Constraints: + +n == nums.length +1 <= n <= 300 +nums[i] is either 0, 1, or 2. + +Approach: +1. applied a basic sorting algorithm + +Time Complexity: O(n^2) +Space Complexity: O(1) + +Contributor: SamaKool +*/ + +class Solution { +public: + void sortColors(vector& nums) { + int n = nums.size(); + for (int i = n-1; i >= 1; i--){ + int did_swap = 0; + for (int j = 0; j <= i-1; j++){ + if(nums[j] > nums[j+1]){ + int temp = nums[j]; + nums[j] = nums[j+1]; + nums[j+1] = temp; + did_swap += 1; + } + } + if(did_swap == 0){ + break; + } + } + } +}; \ No newline at end of file diff --git a/DomainsLeaderboards/Overall.md b/DomainsLeaderboards/Overall.md index 8fc63ea2..efdc7daa 100644 --- a/DomainsLeaderboards/Overall.md +++ b/DomainsLeaderboards/Overall.md @@ -14,25 +14,26 @@ Welcome to the ProjectHive Leaderboard! This page automatically tracks all contr | 🥈 | [@Aaditya-2407](https://github.com/Aaditya-2407) | 6 | 1 (Frontend) | Recent | | 🥉 | [@Ogagaoghene](https://github.com/Ogagaoghene) | 5 | 1 (Backend) | Recent | | 4 | [@k4niz](https://github.com/k4niz) | 4 | 4 (AI-ML, AR-VR, FullStack, IoT) | Recent | -| 5 | [@GayatriVitkar](https://github.com/GayatriVitkar) | 3 | 1 (CompetitiveProgramming) | Recent | -| 6 | [@Ansh-1019](https://github.com/Ansh-1019) | 2 | 1 (AI-ML) | Recent | -| 7 | [@vatsalgupta2004](https://github.com/vatsalgupta2004) | 2 | 2 (AI-ML, Frontend) | Recent | -| 8 | [@Dhiraj201226](https://github.com/Dhiraj201226) | 2 | 2 (AI-ML, Frontend) | Recent | +| 5 | [@Ansh-1019](https://github.com/Ansh-1019) | 2 | 1 (AI-ML) | Recent | +| 6 | [@vatsalgupta2004](https://github.com/vatsalgupta2004) | 2 | 2 (AI-ML, Frontend) | Recent | +| 7 | [@Dhiraj201226](https://github.com/Dhiraj201226) | 2 | 2 (AI-ML, Frontend) | Recent | +| 8 | [@GayatriVitkar](https://github.com/GayatriVitkar) | 2 | 1 (CompetitiveProgramming) | Recent | | 9 | [@Mansi13-6](https://github.com/Mansi13-6) | 2 | 1 (Frontend) | Recent | | 10 | [@Utkarsh-660](https://github.com/Utkarsh-660) | 2 | 1 (Frontend) | Recent | | 11 | [@alisha1510](https://github.com/alisha1510) | 2 | 1 (Frontend) | Recent | -| 12 | [@Mmadan128](https://github.com/Mmadan128) | 1 | 1 (AI-ML) | Recent | -| 13 | [@AksharGoyal](https://github.com/AksharGoyal) | 1 | 1 (Backend) | Recent | -| 14 | [@SOHAM-GADEKAR](https://github.com/SOHAM-GADEKAR) | 1 | 1 (Frontend) | Recent | -| 15 | [@GayatriVitkarcd](https://github.com/GayatriVitkarcd) | 1 | 1 (Frontend) | Recent | -| 16 | [@MeghPatel-007](https://github.com/MeghPatel-007) | 1 | 1 (Frontend) | Recent | -| 17 | [@SanjeevDeori](https://github.com/SanjeevDeori) | 1 | 1 (Frontend) | Recent | -| 18 | [@Tanmay-Kad](https://github.com/Tanmay-Kad) | 1 | 1 (Frontend) | Recent | -| 19 | [@Soham-Gadekar](https://github.com/Soham-Gadekar) | 1 | 1 (Frontend) | Recent | -| 20 | [@jeturgavli](https://github.com/jeturgavli) | 1 | 1 (Frontend) | Recent | -| 21 | [@snehal492006](https://github.com/snehal492006) | 1 | 1 (Frontend) | Recent | -| 22 | [@Tanushri1307](https://github.com/Tanushri1307) | 1 | 1 (Frontend) | Recent | -| 23 | [@Keron](https://github.com/Keron) | 1 | 1 (Frontend) | Recent | +| 12 | [@SamaKool](https://github.com/SamaKool) | 1 | 1 (CompetitiveProgramming) | Recent | +| 13 | [@Mmadan128](https://github.com/Mmadan128) | 1 | 1 (AI-ML) | Recent | +| 14 | [@AksharGoyal](https://github.com/AksharGoyal) | 1 | 1 (Backend) | Recent | +| 15 | [@SOHAM-GADEKAR](https://github.com/SOHAM-GADEKAR) | 1 | 1 (Frontend) | Recent | +| 16 | [@GayatriVitkarcd](https://github.com/GayatriVitkarcd) | 1 | 1 (Frontend) | Recent | +| 17 | [@MeghPatel-007](https://github.com/MeghPatel-007) | 1 | 1 (Frontend) | Recent | +| 18 | [@SanjeevDeori](https://github.com/SanjeevDeori) | 1 | 1 (Frontend) | Recent | +| 19 | [@Tanmay-Kad](https://github.com/Tanmay-Kad) | 1 | 1 (Frontend) | Recent | +| 20 | [@Soham-Gadekar](https://github.com/Soham-Gadekar) | 1 | 1 (Frontend) | Recent | +| 21 | [@jeturgavli](https://github.com/jeturgavli) | 1 | 1 (Frontend) | Recent | +| 22 | [@snehal492006](https://github.com/snehal492006) | 1 | 1 (Frontend) | Recent | +| 23 | [@Tanushri1307](https://github.com/Tanushri1307) | 1 | 1 (Frontend) | Recent | +| 24 | [@Keron](https://github.com/Keron) | 1 | 1 (Frontend) | Recent | --- @@ -42,7 +43,8 @@ Welcome to the ProjectHive Leaderboard! This page automatically tracks all contr | Contributor | Contributions | |-------------|---------------| -| [@GayatriVitkar](https://github.com/GayatriVitkar) | 3 | +| [@GayatriVitkar](https://github.com/GayatriVitkar) | 2 | +| [@SamaKool](https://github.com/SamaKool) | 1 | ### AI-ML diff --git a/HallOfFame/README.md b/HallOfFame/README.md index 79b8fec3..ad424bb1 100644 --- a/HallOfFame/README.md +++ b/HallOfFame/README.md @@ -86,13 +86,13 @@ Our Hall of Fame recognizes outstanding individuals who have made significant co
-GayatriVitkar +Ansh-1019 -**[@GayatriVitkar](https://github.com/GayatriVitkar)** +**[@Ansh-1019](https://github.com/Ansh-1019)** -*Contributions: 3 PRs across 1 domain(s)* +*Contributions: 2 PRs across 1 domain(s)* -*Domains: CompetitiveProgramming* +*Domains: AI-ML*
@@ -102,13 +102,13 @@ Our Hall of Fame recognizes outstanding individuals who have made significant co
-Ansh-1019 +vatsalgupta2004 -**[@Ansh-1019](https://github.com/Ansh-1019)** +**[@vatsalgupta2004](https://github.com/vatsalgupta2004)** -*Contributions: 2 PRs across 1 domain(s)* +*Contributions: 2 PRs across 2 domain(s)* -*Domains: AI-ML* +*Domains: AI-ML, Frontend*
@@ -118,9 +118,9 @@ Our Hall of Fame recognizes outstanding individuals who have made significant co
-vatsalgupta2004 +Dhiraj201226 -**[@vatsalgupta2004](https://github.com/vatsalgupta2004)** +**[@Dhiraj201226](https://github.com/Dhiraj201226)** *Contributions: 2 PRs across 2 domain(s)* @@ -134,13 +134,13 @@ Our Hall of Fame recognizes outstanding individuals who have made significant co
-Dhiraj201226 +GayatriVitkar -**[@Dhiraj201226](https://github.com/Dhiraj201226)** +**[@GayatriVitkar](https://github.com/GayatriVitkar)** -*Contributions: 2 PRs across 2 domain(s)* +*Contributions: 2 PRs across 1 domain(s)* -*Domains: AI-ML, Frontend* +*Domains: CompetitiveProgramming*