From afadfdbe1e1761c812dc2b1adc86367ab031bde4 Mon Sep 17 00:00:00 2001 From: Saumya Mishra Date: Fri, 23 Oct 2020 16:49:30 +0530 Subject: [PATCH 1/3] Create sum_of_substrings_of_a_given_num.cpp Algorithm to find the sum of all substrings of a given number --- .../sum_of_substrings_of_a_given_num.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Dynamic_Programming/sum_of_substrings_of_a_given_num.cpp diff --git a/Dynamic_Programming/sum_of_substrings_of_a_given_num.cpp b/Dynamic_Programming/sum_of_substrings_of_a_given_num.cpp new file mode 100644 index 0000000..004dcd0 --- /dev/null +++ b/Dynamic_Programming/sum_of_substrings_of_a_given_num.cpp @@ -0,0 +1,18 @@ +// Algorithm to find the sum of all substrings of a given number +// Example: Input: S = 1234 Output: 1670 Explanation: Sum = 1 + 2 + 3 + 4 + 12 + … + +long long sumSubstrings(string s){ + const int p = 1000000007; + int n = s.length(); + long long dp[n]; + dp[0] = (s[0]-'0'); + long long sum=dp[0]; + for(int i=1;ip){ + sum = (sum%p); + } + } + return sum; +} From 8a16f2f86920c998c803831bd8b03302547b42b4 Mon Sep 17 00:00:00 2001 From: Saumya Mishra Date: Tue, 27 Oct 2020 10:16:59 +0530 Subject: [PATCH 2/3] Given an array of strings group anagrams together --- Hashing/Group_anagrams_together.cpp | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Hashing/Group_anagrams_together.cpp diff --git a/Hashing/Group_anagrams_together.cpp b/Hashing/Group_anagrams_together.cpp new file mode 100644 index 0000000..e9979f2 --- /dev/null +++ b/Hashing/Group_anagrams_together.cpp @@ -0,0 +1,37 @@ +// Practice que from gfg +// Given an array of words, print the count of all anagrams together in sorted order (increasing order of counts). +// For example, if the given array is {“cat”, “dog”, “tac”, “god”, “act”}, then grouped anagrams are “(dog, god) (cat, tac, act)”. So the output will be 2 3. + + + +#include +#include +using namespace std; + +int main() { + int t; + cin>>t; + while(t--){ + vector v; + int N; + cin>>N; + string a[N]; + for(int i=0;i>a[i]; + } + unordered_map um; + for(int i=0;i Date: Sat, 31 Oct 2020 10:56:24 +0530 Subject: [PATCH 3/3] code to solve sudoku of size 9*9 Given an incomplete Sudoku configuration in terms of a 9 x 9 2-D square matrix (grid[][]), the task to find a solved Sudoku. For simplicity, you may assume that there will be only one unique solution. --- BackTracking/sudoku.cpp | 64 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 BackTracking/sudoku.cpp diff --git a/BackTracking/sudoku.cpp b/BackTracking/sudoku.cpp new file mode 100644 index 0000000..60d9de4 --- /dev/null +++ b/BackTracking/sudoku.cpp @@ -0,0 +1,64 @@ +// Problem from GFG + +bool isSafe(int i, int j,int num,int grid[9][9]){ + for(int p=0;p<9;p++){ + if(grid[i][p]==num){ + return false; + } + if(grid[p][j]==num){ + return false; + } + } + + int s = sqrt(9); + i = i - (i%s); + j = j - (j%s); + for(int l =0;l