├── Biweekly Contest 105 ├── Buy_Two_Chocolates.cpp ├── Extra_Characters_in_a_String.cpp └── Maximum_Strength_of_a_Group.cpp ├── README.md └── Weekly Contest 347 ├── Difference of Number of Distinct Values on Diagonals.cpp ├── Minimum Cost to Make All Characters Equal.cpp └── Remove_Trailing_Zeros_from_a_String.cpp /Biweekly Contest 105/Buy_Two_Chocolates.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rpatel9675/Leetcode/23b487f1cc081b2cba9fd8a8a4247a9052038b0c/Biweekly Contest 105/Buy_Two_Chocolates.cpp -------------------------------------------------------------------------------- /Biweekly Contest 105/Extra_Characters_in_a_String.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rpatel9675/Leetcode/23b487f1cc081b2cba9fd8a8a4247a9052038b0c/Biweekly Contest 105/Extra_Characters_in_a_String.cpp -------------------------------------------------------------------------------- /Biweekly Contest 105/Maximum_Strength_of_a_Group.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rpatel9675/Leetcode/23b487f1cc081b2cba9fd8a8a4247a9052038b0c/Biweekly Contest 105/Maximum_Strength_of_a_Group.cpp -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Leetcode 2 | https://leetcode.com/pprl735757/ 3 | Leetcode contest solutions 4 | -------------------------------------------------------------------------------- /Weekly Contest 347/Difference of Number of Distinct Values on Diagonals.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[][] differenceOfDistinctValues(int[][] grid) { 3 | int N = grid.length, M = grid[0].length; 4 | int[][] res = new int[N][M]; 5 | for (int i = 0; i < N; i++) { 6 | for (int j = 0; j < M; j++) { 7 | HashSet set1 = new HashSet<>(), set2 = new HashSet<>(); 8 | for (int k = 1; i - k >= 0 && j - k >= 0; k++) { 9 | set1.add(grid[i - k][j - k]); 10 | } 11 | for (int k = 1; i + k < N && j + k < M; k++) { 12 | set2.add(grid[i + k][j + k]); 13 | } 14 | res[i][j] = Math.abs(set1.size() - set2.size()); 15 | } 16 | } 17 | return res; 18 | } 19 | } -------------------------------------------------------------------------------- /Weekly Contest 347/Minimum Cost to Make All Characters Equal.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | long long minimumCost(string s) { 4 | long long ans = 0, n = s.length(), i, j, k; 5 | for (i = 0; i < n - 1; i++) { 6 | if (s[i] != s[i + 1]) { 7 | ans += min(i + 1, n - (i + 1)); 8 | } 9 | } 10 | return ans; 11 | } 12 | }; -------------------------------------------------------------------------------- /Weekly Contest 347/Remove_Trailing_Zeros_from_a_String.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string removeTrailingZeros(string num) { 4 | int count=0; 5 | for(int i=num.size()-1;i>=0;i--){ 6 | if(num[i]=='0') count++; 7 | else break; 8 | } 9 | string s=""; 10 | for(int i=0;i