From 188ced7d69ba65689475b1794fa1b48df2985470 Mon Sep 17 00:00:00 2001 From: Ayushjain1722 Date: Fri, 5 Oct 2018 20:58:03 +0530 Subject: [PATCH 001/109] Git Rocks --- PATTERN2.CPP | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 PATTERN2.CPP diff --git a/PATTERN2.CPP b/PATTERN2.CPP new file mode 100644 index 0000000..18a269d --- /dev/null +++ b/PATTERN2.CPP @@ -0,0 +1,81 @@ +#include +#include +void main() +{ + clrscr(); + int n,i,j,k; + cout<<"Enter Value Of n: "; + cin>>n; + int space=n-1; + for(i=1; i<=n;i++) + { + cout<=1;k--) + { + cout<<" "; + } + space--; + for(j=1; j<=i; j++) + cout<=1; j--) + cout<>n; + space=n-1; + for(i=1; i<=n;i++) + { + cout<=1;k--) + cout<<" "; + for (j=1; j<=(2*i)-1; j++) + cout<<'*'; + space--; + } + space=1; + for (i=1; i<=n-1; i++) + { + cout<=1; k--) + cout<<" "; + for(j=1;j<=2*(n-i)-1;j++) + cout<<'*'; + space++; + } + getch(); +} + +/* +Enter Value Of n: 5 + + + 1 + 121 + 12321 + 1234321 +123454321 + +Enter Value Of n: 6 + + * + *** + ***** + ******* + ********* +*********** + ********* + ******* + ***** + *** + * + +*/ + + + + + + From 3e3fa50443927e8f5a358b1aa9213b47e69b49c4 Mon Sep 17 00:00:00 2001 From: Ayushjain1722 Date: Tue, 9 Oct 2018 11:51:14 +0530 Subject: [PATCH 002/109] Git Rocks --- AAL/Aditya And Ladders.txt | 31 +++++++++++++++++++++++++++++++ AAL/x.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 AAL/Aditya And Ladders.txt create mode 100644 AAL/x.cpp diff --git a/AAL/Aditya And Ladders.txt b/AAL/Aditya And Ladders.txt new file mode 100644 index 0000000..273d877 --- /dev/null +++ b/AAL/Aditya And Ladders.txt @@ -0,0 +1,31 @@ +Aditya is fond of ladders. Everyday he goes through pictures of ladders online but unfortunately today he ran out of ladder pictures online. Write a program to print “ladder with N steps”, which he can use to get his daily dose of ladder love. + +INPUT: +Input contains integer N, the number of steps in the ladder + +OUTPUT: + +Print the ladder with the gap between two side rails being 3 spaces(“ “). + +Check the sample output for format of printing the ladder. + +CONSTRAINTS: + +1<=N<=40 + +Sample Input : 4 +Sample Output: +* * +* * +***** +* * +* * +***** +* * +* * +***** +* * +* * +***** +* * +* * \ No newline at end of file diff --git a/AAL/x.cpp b/AAL/x.cpp new file mode 100644 index 0000000..65b0a5b --- /dev/null +++ b/AAL/x.cpp @@ -0,0 +1,31 @@ +#include + +using namespace std; + +int main() + +{ + +int N,i=0; + +cin>>N; + +while(i Date: Wed, 2 Oct 2019 14:14:11 +0530 Subject: [PATCH 003/109] Create QUESTION.txt ADDED QUESTION FOR TRUEDARE --- TRUEDARE/QUESTION.txt | 79 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 TRUEDARE/QUESTION.txt diff --git a/TRUEDARE/QUESTION.txt b/TRUEDARE/QUESTION.txt new file mode 100644 index 0000000..a97ff54 --- /dev/null +++ b/TRUEDARE/QUESTION.txt @@ -0,0 +1,79 @@ +Ram and Shyam are playing a game of Truth and Dare. In this game, Shyam will ask Ram to perform tasks of two types: + +Truth task: Ram has to truthfully answer a question. +Dare task: Ram has to perform a given task. +Each task is described by an integer. (If a truth task and a dare task are described by the same integer, they are still different tasks.) You are given four lists of tasks: + +Tr,1,Tr,2,…,Tr,tr: the truth tasks Ram can perform. +Dr,1,Dr,2,…,Dr,dr: the dare tasks Ram can perform. +Ts,1,Ts,2,…,Ts,ts: the truth tasks Shyam can ask Ram to perform. +Ds,1,Ds,2,…,Ds,ds: the dare tasks Shyam can ask Ram to perform. +Note that the elements of these lists are not necessarily distinct, each task may be repeated any number of times in each list. + +Shyam wins the game if he can find a task Ram cannot perform. Ram wins if he performs all tasks Shyam asks him to. Find the winner of the game. + +Let's take an example where Ram can perform truth tasks 3, 2 and 5 and dare tasks 2 and 100, and Shyam can give him truth tasks 2 and 3 and a dare task 100. We can see that whichever truth or dare tasks Shyam asks Ram to perform, Ram can easily perform them, so he wins. However, if Shyam can give him dare tasks 3 and 100, then Ram will not be able to perform dare task 3, so Shyam wins. + +Input +The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. +The first line of each test case contains a single integer tr. +The second line contains tr space-separated integers Tr,1,Tr,2,…,Tr,tr. +The third line contains a single integer dr. +The fourth line contains dr space-separated integers Dr,1,Dr,2,…,Dr,dr. +The fifth line contains a single integer ts. +The sixth line contains ts space-separated integers Ts,1,Ts,2,…,Ts,ts. +The seventh line contains a single integer ds. +The eighth line contains ds space-separated integers Ds,1,Ds,2,…,Ds,ds. +Output +For each test case, print a single line containing the string "yes" if Ram wins the game or "no" otherwise. + +Constraints +1≤T≤100 +1≤tr,dr,ts,ds≤100 +1≤Tr,i≤100 for each valid i +1≤Dr,i≤100 for each valid i +1≤Ts,i≤100 for each valid i +1≤Ds,i≤100 for each valid i +Example Input +4 +2 +1 2 +3 +1 3 2 +1 +2 +2 +3 2 +2 +1 2 +3 +1 3 2 +1 +2 +3 +3 2 4 +3 +3 2 5 +2 +2 100 +1 +2 +1 +100 +2 +1 2 +3 +1 3 2 +1 +2 +3 +3 2 2 +Example Output +yes +no +yes +yes +Explanation +Example case 1: Ram's truth tasks are [1,2] and his dare tasks are [1,3,2]. Shyam's truth tasks are [2] and his dare tasks are [3,2]. Ram can perform all tasks Shyam gives him. + +Example case 2: Ram's truth tasks are [1,2] and his dare tasks are [1,3,2]. Shyam's truth tasks are [2] and his dare tasks are [3,2,4]. If Shyam asks Ram to perform dare task 4, Ram will not be able to do it. From 1fe1fc6556daecdd22f78c12144b1fd45ebb8f8e Mon Sep 17 00:00:00 2001 From: abhaypatro <47801727+abhaypatro@users.noreply.github.com> Date: Wed, 2 Oct 2019 14:14:52 +0530 Subject: [PATCH 004/109] Create SOLUTION.txt ADDED SOLUTION FOR TRUEDARE --- TRUEDARE/SOLUTION.txt | 75 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 TRUEDARE/SOLUTION.txt diff --git a/TRUEDARE/SOLUTION.txt b/TRUEDARE/SOLUTION.txt new file mode 100644 index 0000000..a82eb0c --- /dev/null +++ b/TRUEDARE/SOLUTION.txt @@ -0,0 +1,75 @@ +#include +using namespace std; +int main() +{ + int t,a,i,j,c,e,g,x,y; + cin>>t; + while(t>0) + { x=0; + y=0; + cin>>a; + int b[a]; + for( i=0;i>b[i]; + + cin>>c; + int d[c]; + for( i=0; i>d[i]; + + cin>>e; + int f[e]; + for(i=0;i>f[i]; + + cin>>g; + int h[g]; + for(i=0;i>h[i]; + + for(i=0;i Date: Wed, 2 Oct 2019 14:52:32 +0530 Subject: [PATCH 005/109] Added Tower of Hanoi Problem --- Tower-of-Hanoi/Hanoi.java | 22 ++++++++++++++++++++++ Tower-of-Hanoi/Tower of Hanoi.txt | 16 ++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 Tower-of-Hanoi/Hanoi.java create mode 100644 Tower-of-Hanoi/Tower of Hanoi.txt diff --git a/Tower-of-Hanoi/Hanoi.java b/Tower-of-Hanoi/Hanoi.java new file mode 100644 index 0000000..a6e0571 --- /dev/null +++ b/Tower-of-Hanoi/Hanoi.java @@ -0,0 +1,22 @@ +import java.util.Scanner; + +class Hanoi{ + public static void main(String[] args){ + Scanner newInput = new Scanner(System.in); + System.out.print("Enter the value of n: "); + int n = newInput.nextInt(); + char[] rod = new char[]{'A','B','C'}; + move(n,rod[0],rod[2],rod[1]); + } + + + public static void move(int n, char from, char to, char aux){ + if (n == 1) { + System.out.println("Move " + n + " From " + from + " to " + to); + return; + } + move(n-1,from,aux,to); + System.out.println("Move " + n + " From " + from + " to " + to); + move(n-1,aux,to,from); + } +} \ No newline at end of file diff --git a/Tower-of-Hanoi/Tower of Hanoi.txt b/Tower-of-Hanoi/Tower of Hanoi.txt new file mode 100644 index 0000000..88ff2b5 --- /dev/null +++ b/Tower-of-Hanoi/Tower of Hanoi.txt @@ -0,0 +1,16 @@ +Tower of Hanoi is a mathematical puzzle where we have three rods and n disks. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules: +1) Only one disk can be moved at a time. +2) Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack. +3) No disk may be placed on top of a smaller disk. + +The most ideal solution to this problem has 2^n-1 steps, where, n = number of disks. + +For example: +For 2 disks : +Let rod 1 = 'A', rod 2 = 'B', rod 3 = 'C'. +Number of Steps = 2^2-1 = 3. + +Therefore, +Step 1 : Shift first disk from 'A' to 'B'. +Step 2 : Shift second disk from 'A' to 'C'. +Step 3 : Shift first disk from 'B' to 'C'. \ No newline at end of file From ee742be6482272c13aad901141928f4cd01e9d87 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 2 Oct 2019 15:12:56 +0530 Subject: [PATCH 006/109] binary_search --- binary_search/binary_search.txt | 3 +++ binary_search/bs.class | Bin 0 -> 995 bytes binary_search/bs.ctxt | 7 +++++++ binary_search/bs.java | 29 +++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 binary_search/binary_search.txt create mode 100644 binary_search/bs.class create mode 100644 binary_search/bs.ctxt create mode 100644 binary_search/bs.java diff --git a/binary_search/binary_search.txt b/binary_search/binary_search.txt new file mode 100644 index 0000000..352fb59 --- /dev/null +++ b/binary_search/binary_search.txt @@ -0,0 +1,3 @@ +Binary search + +Question- Given a sorted array of numbers and a number, find if the given number exists in the array in O(nlogn) time and O(1) space. \ No newline at end of file diff --git a/binary_search/bs.class b/binary_search/bs.class new file mode 100644 index 0000000000000000000000000000000000000000..31b19663b4c7f2f22368ab8f55747f390ebbd3fb GIT binary patch literal 995 zcmZuwOHUI~6#nkKTUy@57ln$brNtH>sV0zdVKgBr)})4{vXGf}D1+^k%uG%ADXwH; z!iJ43AW_2)FmdDWQS_TB#F((S_ndp~Ip5<>=KI-~Qvi?gD2W8-b=*!u!hE#dN#HK> z1{RViplD!G$2|dU#r53K6p-@^>jKKNUds^}sk)x?vfs5G|FvazSQ)SOnpS7s^4;is zUR1(uH{ej!4wePdw(D8`-rK;j{N^^H^Bb$H3vUQ*`M!X(u__=uE=JXN+uI>WJI)q^ z+;v+7sE1bb-I}#~0pGP;_D|(Esyo(utK6}?cDWwA0W513aXV zi@F=+yk3~w^__ri0;B)r)$ARo`G2Xt7lckXQq<=~X5hu`m0!_FNIQ{oClS2? z_h|ShyER6$cxuWOC7V$;)lNk%X4KO3K2+r}&OTu%qbe=)013v;iV{~p@}y+<|NM{- zi6FQm>LN$BsNTl&E5b8X{%pfc;!qbe_Outky(^lM<1ZafO-8 z&L_l~g2KrqTw|uPrpKHoItJ`-;xbksWlX} z)=;%tL(^*w-Keb@W^pll4CMockD!ig$IuTj6r~2!=vfB_XJ`zRW{^HdVRMvJq?igx yP0~iD3Ij@HF~gI=e{`0X1^Z{YCTVJpcac3gHjsvNhKdeJ$4#NLagJjWZv6%HBC9R{ literal 0 HcmV?d00001 diff --git a/binary_search/bs.ctxt b/binary_search/bs.ctxt new file mode 100644 index 0000000..487f1ee --- /dev/null +++ b/binary_search/bs.ctxt @@ -0,0 +1,7 @@ +#BlueJ class context +comment0.target=bs +comment1.params=arr\ n +comment1.target=boolean\ binary_search(int[],\ int) +comment2.params=args +comment2.target=void\ main(java.lang.String[]) +numComments=3 diff --git a/binary_search/bs.java b/binary_search/bs.java new file mode 100644 index 0000000..c5eb9f4 --- /dev/null +++ b/binary_search/bs.java @@ -0,0 +1,29 @@ +class bs +{ + public boolean binary_search(int arr[], int n) + { + int right;int left; int mid; + right= arr.length; + left=0; + do{ + mid= (right+left)/2; + if(arr[mid]==n) + return true; + if(arr[mid]>n) + right= mid-1; + else + left= mid+1; + }while((arr[mid]!=n)&&(left!=right)); + return false; + } + public static void main(String args[]) + { + bs obj = new bs(); + int a[]={1,2,3,4,5}; + int n= 5; + if(obj.binary_search(a,n)) + System.out.println("Element found"); + else + System.out.println("Element is not present"); + } +} From bbe35f66f846cf69d30239f946ec22e856d756a2 Mon Sep 17 00:00:00 2001 From: chinmay81098 <40710834+chinmay81098@users.noreply.github.com> Date: Wed, 2 Oct 2019 15:53:38 +0530 Subject: [PATCH 007/109] New question Added --- ginortS/Question.txt | 16 ++++++++++++++++ ginortS/Solution.py | 21 +++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 ginortS/Question.txt create mode 100644 ginortS/Solution.py diff --git a/ginortS/Question.txt b/ginortS/Question.txt new file mode 100644 index 0000000..8c8b4c2 --- /dev/null +++ b/ginortS/Question.txt @@ -0,0 +1,16 @@ +You are given a string S + S contains alphanumeric characters only. + + Your task is to sort the string S in the following manner: + +All sorted lowercase letters are ahead of uppercase letters. +All sorted uppercase letters are ahead of digits. +All sorted odd digits are ahead of sorted even digits. + +Sample Input + +Sorting1234 + +Sample Output + +ginortS1234 \ No newline at end of file diff --git a/ginortS/Solution.py b/ginortS/Solution.py new file mode 100644 index 0000000..252193c --- /dev/null +++ b/ginortS/Solution.py @@ -0,0 +1,21 @@ +s=input() +upperCase=[] +lowerCase=[] +even=[] +odd=[] +for i in s: + if i >= 'A' and i<= 'Z': + upperCase.append(i) + elif i >='a' and i<= 'z': + lowerCase.append(i) + elif int(i)%2 == 0: + even.append(i) + elif int(i)%2 != 0: + odd.append(i) + +upperCase.sort() +lowerCase.sort() +even.sort() +odd.sort() + +print("".join(lowerCase+upperCase+odd+even)) From c0c526e3d469b33abf458a9d4b764ced75ddcf88 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 2 Oct 2019 15:55:31 +0530 Subject: [PATCH 008/109] WATCHFB --- WATCHFB/Main.class | Bin 0 -> 1726 bytes WATCHFB/Main.ctxt | 19 +++++ WATCHFB/Main.java | 195 ++++++++++++++++++++++++++++++++++++++++++++ WATCHFB/WATCHFB.txt | 53 ++++++++++++ 4 files changed, 267 insertions(+) create mode 100644 WATCHFB/Main.class create mode 100644 WATCHFB/Main.ctxt create mode 100644 WATCHFB/Main.java create mode 100644 WATCHFB/WATCHFB.txt diff --git a/WATCHFB/Main.class b/WATCHFB/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..539b6a756893fe3aae6e3be3b23164a9711876b4 GIT binary patch literal 1726 zcmb7EOHi9t6#h@LF|2kyjOW!S5sTf^M~ zTURoj%J!n5c52 zbe6%ZuE}+8KAD)=+=!S9n-uBC05Oj4i)$EkVF>pz%Yi|nQ;`JarCSEa z4kpG4VuL6?KbuQT(?gjCinx-Qw%+tiKF2mB^l4(MY`m^Q^+%)0L~ojxavInpPbpfz zo|_`P#=gELf-z_EG%7_HVv9=={DvC?Zx9>Jq)|#`wwA%a#{+fnaGKT61j2%kw1THL z?!w*LybQTusQsiiLwE=`karag5I~S8J3^?WgwE#Uu%HT%2UcJjU4(fVme{r>Sa+?! zHo6RLz#OpzEa5Y<(;l_jqnbTxw@01kh+7#&Jm!cu;0<`rh~GGuD|#&ID{lUvFX+FB zvS^^l*rOrEoLoTFA{-UYCAcgRchDELb2$t6Hc)OkUD5>uRD_~V+7xgu7z)}?o+@hH z^jz06l>$x#1BSNMuzD8_0rvttDu^;Iz_}i8-K&6y4VMM{50|F3D0N1ZH54iUb0}SG zKI)aim0yoqNWW3-FhjNDXLOKe;KU4j_b3~XWk++UM;==-hh{v6797S7JkC$i5q^fA z;1hY01OF6;@iZR6GdO@}k;XAvKZkidPmAM}zJQ~62`}PhyoM8a1Fv8Kui`zPPUCfa zf;VvQ*;2m7XDSS`u4|pFx;sfUPA%4L}_#GeP4}2P6!g;C1 z1*yZL)MH87@r88ZlI+2XbmL3ekFTT;M`Q?D8Nt`axSi!}_J|s+YGUoj->5;DvSIv* zT5^7(`Hhb{%z-?BpZK!F9LWv|VKY6vsF&@mO&C^el_uOoPJLP$u!Wo*EwY7G3$v0t zWHW9?1Kfy6HLF<77g8ggXe4J*LyacZ6>v%n+pwJ@U(S46s5POI2wM4e%&a(AMb9de zv}(9TgGn^l_@Y*stZReB!k@4>RP@1jtwNLmP*b}}bMU{)-2TJedR3&q2vu+^6EWeo Fe*oo~PfY*- literal 0 HcmV?d00001 diff --git a/WATCHFB/Main.ctxt b/WATCHFB/Main.ctxt new file mode 100644 index 0000000..b2ed59f --- /dev/null +++ b/WATCHFB/Main.ctxt @@ -0,0 +1,19 @@ +#BlueJ class context +comment0.target=Main +comment1.params=stream +comment1.target=LCSin(java.io.InputStream) +comment2.params= +comment2.target=int\ read() +comment3.params= +comment3.target=int\ readInt() +comment4.params=c +comment4.target=boolean\ isSpaceChar(int) +comment5.params= +comment5.target=java.lang.String\ readString() +comment6.params= +comment6.target=byte\ readByte() +comment7.params= +comment7.target=long\ readLong() +comment8.params=args +comment8.target=void\ main(java.lang.String[]) +numComments=9 diff --git a/WATCHFB/Main.java b/WATCHFB/Main.java new file mode 100644 index 0000000..430dbef --- /dev/null +++ b/WATCHFB/Main.java @@ -0,0 +1,195 @@ +import java.io.IOException; +import java.io.InputStream; +import java.util.InputMismatchException; +import java.util.Arrays; +class LCSin +{ + private InputStream stream; + private byte[] buf = new byte[1024]; + private int curChar; + private int numChars; + private SpaceCharFilter filter; + public LCSin(InputStream stream) { + this.stream = stream; + } + public interface SpaceCharFilter { + public boolean isSpaceChar(int ch); + } + public int read() { + if (numChars == -1) + throw new InputMismatchException(); + if (curChar >= numChars) { + curChar = 0; + try { + numChars = stream.read(buf); + } catch (IOException e) { + throw new InputMismatchException(); + } + if (numChars <= 0) + return -1; + } + return buf[curChar++]; + } + public int readInt() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + int sgn = 1; + if (c == '-') { + sgn = -1; + c = read(); + } + int res = 0; + do { + if (c < '0' || c > '9') + throw new InputMismatchException(); + res *= 10; + res += c - '0'; + c = read(); + } while (!isSpaceChar(c)); + return res * sgn; + } + public boolean isSpaceChar(int c) { + if (filter != null) + return filter.isSpaceChar(c); + return c==' '||c=='\n'|| c == '\r' || c == '\t' || c == -1; + } + public String readString() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + StringBuilder res = new StringBuilder(); + do { + res.appendCodePoint(c); + c = read(); + } + while (!isSpaceChar(c)); + return res.toString(); + } + public byte readByte() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + byte res = 0; + do { + if (c < '0' || c > '9') + throw new InputMismatchException(); + res *= 10; + res += c - '0'; + c = read(); + } while (!isSpaceChar(c)); + return res; + } + public long readLong() { + int c = read(); + while (isSpaceChar(c)) + c = read(); + int sgn = 1; + if (c == '-') + { + sgn = -1; + c = read(); + } + long res = 0; + do + { + if (c < '0' || c > '9') + throw new InputMismatchException(); + res *= 10; + res += c - '0'; + c = read(); + } + while (!isSpaceChar(c)); + return res * sgn; + } +} + +public class Main +{ + public static void main(String args[]) + { + LCSin br= new LCSin(System.in); + int test= br.readInt(); + StringBuilder sb=new StringBuilder(); + for(int testcase= 0; testcaseprevmax) + { + System.out.println("NO"); + prevmax= max; + prevmin= min; + res= false; + continue; + } + + if((max>prevmax)&&(minprevmax)&&(min==prevmax)) + { + + System.out.println("NO"); + res= false; + prevmax= max; + prevmin= min; + continue; + + } + } + } + } +} \ No newline at end of file diff --git a/WATCHFB/WATCHFB.txt b/WATCHFB/WATCHFB.txt new file mode 100644 index 0000000..248a964 --- /dev/null +++ b/WATCHFB/WATCHFB.txt @@ -0,0 +1,53 @@ +https://www.codechef.com/problems/WATCHFB + +Chef and his son Chefu want to watch a match of their favourite football team playing against another team, which will take place today. + +Unfortunately, Chef is busy in the kitchen preparing lunch, so he cannot watch the match. Therefore, every now and then, Chef asks Chefu about the current scores of the teams and Chefu tells him the score. However, Chefu sometimes does not specify the teams along with the score — for example, he could say "the score is 3 to 6", and there is no way to know just from this statement if it was their favourite team or the other team that scored 6 goals; in different statements, the order of teams may also be different. Other times, Chefu specifies which team scored how many goals. + +Chef asks for the score and receives a reply N times. There are two types of replies: + +1 A B: their favourite team scored A goals and the other team scored B goals +2 A B: one team scored A goals and the other scored B goals +Chef is asking you to help him determine the score of his favourite team after each of Chefu's replies. After each reply, based on the current reply and all previous information (but without any following replies), tell him whether it is possible to certainly determine the number of goals scored by his favourite team. + +Input +The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. +The first line of each test case contains a single integer N. +The following N lines describe Chefu's replies in the format described above. +Output +For each of Chefu's replies, print a single line containing the string "YES" if it is possible to determine the score of Chef's favourite team after this reply or "NO" if it is impossible. + +Constraints +1=T=100 +1=N=104 +0=A,B=109 +the sum of N over all test cases does not exceed 105 +there is at least one valid sequence of scored goals consistent with all replies +Subtasks +Subtask #1 (100 points): original constraints + +Example Input +1 +6 +2 0 1 +1 3 1 +2 2 4 +2 5 6 +2 8 8 +2 9 10 +Example Output +NO +YES +YES +NO +YES +NO +Explanation +Example case 1: + +Reply 1: Chef cannot know who scored the first goal. +Reply 2: Chefu told Chef that their favourite team has scored 3 goals so far. +Reply 3: Chef can conclude that his favourite team has scored 4 goals, since it already scored 3 goals earlier. +Reply 4: the favourite team could have scored 5 or 6 goals, but there is no way to know which option is correct. +Reply 5: since there is a tie, Chef knows that his favourite team has scored 8 goals. +Reply 6: again, Chef cannot know if his favourite team has scored 9 or 10 goals. \ No newline at end of file From 6471fe62a080808b818063c62bd956042866291c Mon Sep 17 00:00:00 2001 From: amcs1729 <51089276+amcs1729@users.noreply.github.com> Date: Wed, 2 Oct 2019 15:58:27 +0530 Subject: [PATCH 009/109] Update WATCHFB.txt --- WATCHFB/WATCHFB.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/WATCHFB/WATCHFB.txt b/WATCHFB/WATCHFB.txt index 248a964..68b7e03 100644 --- a/WATCHFB/WATCHFB.txt +++ b/WATCHFB/WATCHFB.txt @@ -1,8 +1,13 @@ +The solution given is created by the author and using it without prior written permission from the author can lead to legal actions. +Please contact amcs1729@gmail.com for any queries + + + https://www.codechef.com/problems/WATCHFB Chef and his son Chefu want to watch a match of their favourite football team playing against another team, which will take place today. -Unfortunately, Chef is busy in the kitchen preparing lunch, so he cannot watch the match. Therefore, every now and then, Chef asks Chefu about the current scores of the teams and Chefu tells him the score. However, Chefu sometimes does not specify the teams along with the score — for example, he could say "the score is 3 to 6", and there is no way to know just from this statement if it was their favourite team or the other team that scored 6 goals; in different statements, the order of teams may also be different. Other times, Chefu specifies which team scored how many goals. +Unfortunately, Chef is busy in the kitchen preparing lunch, so he cannot watch the match. Therefore, every now and then, Chef asks Chefu about the current scores of the teams and Chefu tells him the score. However, Chefu sometimes does not specify the teams along with the score — for example, he could say "the score is 3 to 6", and there is no way to know just from this statement if it was their favourite team or the other team that scored 6 goals; in different statements, the order of teams may also be different. Other times, Chefu specifies which team scored how many goals. Chef asks for the score and receives a reply N times. There are two types of replies: @@ -50,4 +55,4 @@ Reply 2: Chefu told Chef that their favourite team has scored 3 goals so far. Reply 3: Chef can conclude that his favourite team has scored 4 goals, since it already scored 3 goals earlier. Reply 4: the favourite team could have scored 5 or 6 goals, but there is no way to know which option is correct. Reply 5: since there is a tie, Chef knows that his favourite team has scored 8 goals. -Reply 6: again, Chef cannot know if his favourite team has scored 9 or 10 goals. \ No newline at end of file +Reply 6: again, Chef cannot know if his favourite team has scored 9 or 10 goals. From fc9477aac8f9e0c98d8d3ecd77a853791391d2a9 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 2 Oct 2019 16:04:44 +0530 Subject: [PATCH 010/109] ZOMCAV --- ZOMCAV/ZOMCAV.txt | 39 +++++++++++++++++++++ ZOMCAV/codechef.class | Bin 0 -> 2016 bytes ZOMCAV/codechef.ctxt | 5 +++ ZOMCAV/codechef.java | 78 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 ZOMCAV/ZOMCAV.txt create mode 100644 ZOMCAV/codechef.class create mode 100644 ZOMCAV/codechef.ctxt create mode 100644 ZOMCAV/codechef.java diff --git a/ZOMCAV/ZOMCAV.txt b/ZOMCAV/ZOMCAV.txt new file mode 100644 index 0000000..a5c7423 --- /dev/null +++ b/ZOMCAV/ZOMCAV.txt @@ -0,0 +1,39 @@ +The solution given along is written solely by the author and using it anywhere else without prior written permission might result in legal actions taken against the guilty person + + + + + +There are N caves in a row, numbered 1 through N. For each valid i, the radiation power in the i-th cave is Ci. Originally, the radiation level in each cave was 0. Then, for each valid i, the radiation power in cave i increased the radiation levels in the caves i-Ci,…,i+Ci inclusive (if they exist) by 1, so all the caves are radioactive now. + +Radiation is not the only problem, though. There are also N zombies with health levels H1,H2,…,HN. You want to kill all of them by getting them to the caves in such a way that there is exactly one zombie in each cave. A zombie dies in a cave if and only if the radiation level in that cave is equal to the health level of the zombie. Is it possible to kill all the zombies? + +Input +The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. +The first line of each test case contains a single integer N. +The second line contains N space-separated integers C1,C2,…,CN. +The third line contains N space-separated integers H1,H2,…,HN. +Output +For each test case, print a single line containing the string "YES" if it is possible to kill all the zombies or "NO" if it is impossible (without quotes). + +Constraints +1=T=100 +1=N=105 +1=Ci,Hi=109 for each valid i +Subtasks +Subtask #1 (30 points): 1=N=1,000 +Subtask #2 (70 points): original constraints + +Example Input +2 +5 +1 2 3 4 5 +1 2 3 4 5 +5 +1 2 3 4 5 +5 4 3 4 5 +Example Output +NO +YES +Explanation +In both example test cases, the final radiation levels in the caves are (5,5,4,4,3). For example, the radiation power in cave 1 increased the radiation levels in caves 1 and 2 (there is no cave 0) by 1, and the radiation power in cave 4 increased the radiation levels in all caves by 1. \ No newline at end of file diff --git a/ZOMCAV/codechef.class b/ZOMCAV/codechef.class new file mode 100644 index 0000000000000000000000000000000000000000..2b81a216d64c44139c7185d99c8622c1f31d4a21 GIT binary patch literal 2016 zcmZuyU2GIp6#nkcY-i_Zw{&4^7s{`IUC^xpZlRQ-g#xWx7AYd7sGaUk+kx%Qx;ur+ zD{aCfiN0uv4;a%o6NsUW7~+#r6BD0#GCpcF_+kuV>vw1SXK2&8bMCq4eCIpgJ=6X$ z|J6ePZFt|n26SpTs^K*qucOO=f@20kI4+lN11E4&!zlwgdgRh8mp2S#(P!W^ax&>m z1aBHRi~b1CX?RP+d4akPx8(Yr0!mAYTlJV%a0KeJZpk@4F+S{6&e_97dg56xZx_$o z6<6*TovJ_PRt1b~o>}=ZXXG#u#%;GG(AYAVy=-5#TZ?vSw6))_xTVp@lFtC}rW&&AwRTO6j5rmi zaMrO40jwZcwBNV$SNiO7AdiN98s65BqCnk~d8h2VUa6|#0{8viL?!Q>aHX=*CGpa- zT?+{`Qof+|X9@`Fd|b%EsVj{aM{8Y6fKN{m!b@G_iOMhl#!<(r*o8kiMznMmCMQvUv~1;W0k8m z02Ftber{Ql{|A0h^__9T%OOfE>%FR5-eFVAng?>c)~_5b-i`D|C{sbsw7`azR4sY+ zU(C;bv&Zxudj+E_6)!~**7GYN>r8s+Q`dKhKW>@>XiW5v8hl*d&e;GgK9N?{}MyT4d_N&|i zT3H4aOW20>{2L>GLVP%d5O|JOE8l|e@Sa(SyTNf2*Sf%|AW7S*1z;mKai^mhn+d{X z#b8`LAof2%Xy5@y=pNKrglAEg-FqL}93n@Q&dtqt#D>LfMwLc;I9Tfv>eoiQ7OW8^ zqbKx)dI$B%NJ3X~Q@WU0c>DnRK$3VyyRKx6q<$af$2cM1)*Pa3rk*gS8%<{pv74D_ zVB3a$GZULK1Yx3=(&|ty5lg6Q;WJqD#ONvHW)|j%rew^7DJ$+u7(6o5Lm4As+(w4Y(qn=;AcQNW{4@-X!_OUc9}=pAfsv=|vnPv1zIHA*+ytf?3?erdGyk3K={ z9_r)k?xSG_rZnR;rxY?Xjq3ACoiVWrLKm)pXds*Jv zS-vkYD$h$8!4}ASox~1I<9Xb|ZhVLoZZrFH?8O&I<1Y5&OB}#MB7MhyG(X}Xe!?L< zqVH!M#c%w-@dwfW#&KbxOT=+fBymdYM6Y-ey4c66as<9%-EKZxu$2raiMB1^In8=I z=!>%Y7IN5%7-s2{aVGv`jI?6dBSP3oOJ!G2v5QQ@#Q2My@8$?~;4xa5rIE?6WS^oE zd3?_v$bo%+imvndIEb$=yzsnnfcqw^B=vAzr~gvW<)F?E3)6b|bram8T(A z0|pVBN3({I5DP45XlM&ILc_t}_mGA|{1~1f{x6~$`~L?gLr)PFO;1oik9BmZ;t94j ZERd_Zlr9s(XlDVHB@grIpdG@I{{X*Uv)TXv literal 0 HcmV?d00001 diff --git a/ZOMCAV/codechef.ctxt b/ZOMCAV/codechef.ctxt new file mode 100644 index 0000000..6a90e1f --- /dev/null +++ b/ZOMCAV/codechef.ctxt @@ -0,0 +1,5 @@ +#BlueJ class context +comment0.target=codechef +comment1.params=args +comment1.target=void\ main(java.lang.String[]) +numComments=2 diff --git a/ZOMCAV/codechef.java b/ZOMCAV/codechef.java new file mode 100644 index 0000000..81d3c2a --- /dev/null +++ b/ZOMCAV/codechef.java @@ -0,0 +1,78 @@ +import java.util.*; +import java.io.*; +class codechef +{ + public static void main(String args[])throws IOException + { + BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); + int t= Integer.parseInt(br.readLine()); + for(int phi=0; phi Date: Wed, 2 Oct 2019 16:27:07 +0530 Subject: [PATCH 011/109] ZOMCAV --- ZOMCAV/ZOMCAV.txt | 39 +++++++++++++++++++++ ZOMCAV/codechef.class | Bin 0 -> 2016 bytes ZOMCAV/codechef.ctxt | 5 +++ ZOMCAV/codechef.java | 78 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 ZOMCAV/ZOMCAV.txt create mode 100644 ZOMCAV/codechef.class create mode 100644 ZOMCAV/codechef.ctxt create mode 100644 ZOMCAV/codechef.java diff --git a/ZOMCAV/ZOMCAV.txt b/ZOMCAV/ZOMCAV.txt new file mode 100644 index 0000000..a5c7423 --- /dev/null +++ b/ZOMCAV/ZOMCAV.txt @@ -0,0 +1,39 @@ +The solution given along is written solely by the author and using it anywhere else without prior written permission might result in legal actions taken against the guilty person + + + + + +There are N caves in a row, numbered 1 through N. For each valid i, the radiation power in the i-th cave is Ci. Originally, the radiation level in each cave was 0. Then, for each valid i, the radiation power in cave i increased the radiation levels in the caves i-Ci,…,i+Ci inclusive (if they exist) by 1, so all the caves are radioactive now. + +Radiation is not the only problem, though. There are also N zombies with health levels H1,H2,…,HN. You want to kill all of them by getting them to the caves in such a way that there is exactly one zombie in each cave. A zombie dies in a cave if and only if the radiation level in that cave is equal to the health level of the zombie. Is it possible to kill all the zombies? + +Input +The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. +The first line of each test case contains a single integer N. +The second line contains N space-separated integers C1,C2,…,CN. +The third line contains N space-separated integers H1,H2,…,HN. +Output +For each test case, print a single line containing the string "YES" if it is possible to kill all the zombies or "NO" if it is impossible (without quotes). + +Constraints +1=T=100 +1=N=105 +1=Ci,Hi=109 for each valid i +Subtasks +Subtask #1 (30 points): 1=N=1,000 +Subtask #2 (70 points): original constraints + +Example Input +2 +5 +1 2 3 4 5 +1 2 3 4 5 +5 +1 2 3 4 5 +5 4 3 4 5 +Example Output +NO +YES +Explanation +In both example test cases, the final radiation levels in the caves are (5,5,4,4,3). For example, the radiation power in cave 1 increased the radiation levels in caves 1 and 2 (there is no cave 0) by 1, and the radiation power in cave 4 increased the radiation levels in all caves by 1. \ No newline at end of file diff --git a/ZOMCAV/codechef.class b/ZOMCAV/codechef.class new file mode 100644 index 0000000000000000000000000000000000000000..2b81a216d64c44139c7185d99c8622c1f31d4a21 GIT binary patch literal 2016 zcmZuyU2GIp6#nkcY-i_Zw{&4^7s{`IUC^xpZlRQ-g#xWx7AYd7sGaUk+kx%Qx;ur+ zD{aCfiN0uv4;a%o6NsUW7~+#r6BD0#GCpcF_+kuV>vw1SXK2&8bMCq4eCIpgJ=6X$ z|J6ePZFt|n26SpTs^K*qucOO=f@20kI4+lN11E4&!zlwgdgRh8mp2S#(P!W^ax&>m z1aBHRi~b1CX?RP+d4akPx8(Yr0!mAYTlJV%a0KeJZpk@4F+S{6&e_97dg56xZx_$o z6<6*TovJ_PRt1b~o>}=ZXXG#u#%;GG(AYAVy=-5#TZ?vSw6))_xTVp@lFtC}rW&&AwRTO6j5rmi zaMrO40jwZcwBNV$SNiO7AdiN98s65BqCnk~d8h2VUa6|#0{8viL?!Q>aHX=*CGpa- zT?+{`Qof+|X9@`Fd|b%EsVj{aM{8Y6fKN{m!b@G_iOMhl#!<(r*o8kiMznMmCMQvUv~1;W0k8m z02Ftber{Ql{|A0h^__9T%OOfE>%FR5-eFVAng?>c)~_5b-i`D|C{sbsw7`azR4sY+ zU(C;bv&Zxudj+E_6)!~**7GYN>r8s+Q`dKhKW>@>XiW5v8hl*d&e;GgK9N?{}MyT4d_N&|i zT3H4aOW20>{2L>GLVP%d5O|JOE8l|e@Sa(SyTNf2*Sf%|AW7S*1z;mKai^mhn+d{X z#b8`LAof2%Xy5@y=pNKrglAEg-FqL}93n@Q&dtqt#D>LfMwLc;I9Tfv>eoiQ7OW8^ zqbKx)dI$B%NJ3X~Q@WU0c>DnRK$3VyyRKx6q<$af$2cM1)*Pa3rk*gS8%<{pv74D_ zVB3a$GZULK1Yx3=(&|ty5lg6Q;WJqD#ONvHW)|j%rew^7DJ$+u7(6o5Lm4As+(w4Y(qn=;AcQNW{4@-X!_OUc9}=pAfsv=|vnPv1zIHA*+ytf?3?erdGyk3K={ z9_r)k?xSG_rZnR;rxY?Xjq3ACoiVWrLKm)pXds*Jv zS-vkYD$h$8!4}ASox~1I<9Xb|ZhVLoZZrFH?8O&I<1Y5&OB}#MB7MhyG(X}Xe!?L< zqVH!M#c%w-@dwfW#&KbxOT=+fBymdYM6Y-ey4c66as<9%-EKZxu$2raiMB1^In8=I z=!>%Y7IN5%7-s2{aVGv`jI?6dBSP3oOJ!G2v5QQ@#Q2My@8$?~;4xa5rIE?6WS^oE zd3?_v$bo%+imvndIEb$=yzsnnfcqw^B=vAzr~gvW<)F?E3)6b|bram8T(A z0|pVBN3({I5DP45XlM&ILc_t}_mGA|{1~1f{x6~$`~L?gLr)PFO;1oik9BmZ;t94j ZERd_Zlr9s(XlDVHB@grIpdG@I{{X*Uv)TXv literal 0 HcmV?d00001 diff --git a/ZOMCAV/codechef.ctxt b/ZOMCAV/codechef.ctxt new file mode 100644 index 0000000..6a90e1f --- /dev/null +++ b/ZOMCAV/codechef.ctxt @@ -0,0 +1,5 @@ +#BlueJ class context +comment0.target=codechef +comment1.params=args +comment1.target=void\ main(java.lang.String[]) +numComments=2 diff --git a/ZOMCAV/codechef.java b/ZOMCAV/codechef.java new file mode 100644 index 0000000..81d3c2a --- /dev/null +++ b/ZOMCAV/codechef.java @@ -0,0 +1,78 @@ +import java.util.*; +import java.io.*; +class codechef +{ + public static void main(String args[])throws IOException + { + BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); + int t= Integer.parseInt(br.readLine()); + for(int phi=0; phi Date: Wed, 2 Oct 2019 17:09:12 +0530 Subject: [PATCH 012/109] created strong password problem --- StrongPassword/strongpasswordqn.txt | 51 +++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 StrongPassword/strongpasswordqn.txt diff --git a/StrongPassword/strongpasswordqn.txt b/StrongPassword/strongpasswordqn.txt new file mode 100644 index 0000000..12b2952 --- /dev/null +++ b/StrongPassword/strongpasswordqn.txt @@ -0,0 +1,51 @@ +Louise joined a social networking site to stay in touch with her friends. The signup page required her to input a name and a password. However, the password must be strong. The website considers a password to be strong if it satisfies the following criteria: + +Its length is at least 6. +It contains at least one digit. +It contains at least one lowercase English character. +It contains at least one uppercase English character. +It contains at least one special character. The special characters are: !@#$%^&*()-+ +She typed a random string of length n in the password field but wasn't sure if it was strong. Given the string she typed, can you find the minimum number of characters she must add to make her password strong? + +Note: Here's the set of types of characters in a form you can paste in your solution: + +numbers = "0123456789" +lower_case = "abcdefghijklmnopqrstuvwxyz" +upper_case = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +special_characters = "!@#$%^&*()-+" +Input Format + +The first line contains an integer n denoting the length of the string. + +The second line contains a string consisting of n characters, the password typed by Louise. Each character is either a lowercase/uppercase English alphabet, a digit, or a special character. + +Constraints +1 <= n <= 100 + +Output Format + +Print a single line containing a single integer denoting the answer to the problem. + +Sample Input 0 + +3 +Ab1 +Sample Output 0 + +3 +Explanation 0 + +She can make the password strong by adding characters, for example, $hk, turning the password into Ab1$hk which is strong. + +2 characters aren't enough since the length must be at least 6. + +Sample Input 1 + +11 +#HackerRank +Sample Output 1 + +1 +Explanation 1 + +The password isn't strong, but she can make it strong by adding a single digit From 7446d58566ed20199a1aec670aabb6e40e45a69b Mon Sep 17 00:00:00 2001 From: infiltration-x <52758100+infiltration-x@users.noreply.github.com> Date: Wed, 2 Oct 2019 17:11:30 +0530 Subject: [PATCH 013/109] created solution to strong password problem --- StrongPassword/solution.py | 55 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 StrongPassword/solution.py diff --git a/StrongPassword/solution.py b/StrongPassword/solution.py new file mode 100644 index 0000000..01c2e43 --- /dev/null +++ b/StrongPassword/solution.py @@ -0,0 +1,55 @@ +#!/bin/python3 + +import math +import os +import random +import re +import sys + +def minimumNumber(n, password): + # Return the minimum number of characters to make the password strong + numbers = list("0123456789") + lower_case = list("abcdefghijklmnopqrstuvwxyz") + upper_case = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ") + special_characters = list("!@#$%^&*()-+") + count = 0 + length = len(password) + flagn = 0 + flagl = 0 + flagu = 0 + flags = 0 + for i in password: + if i in numbers: + flagn = 1 + for i in password: + if i in lower_case: + flagl = 1 + for i in password: + if i in upper_case: + flagu = 1 + for i in special_characters: + if i in password: + flags = 1 + if flagn == 0: + count+=1 + if flagu == 0: + count+=1 + if flagl == 0: + count+=1 + if flags == 0: + count+=1 + + check = length + count + if check < 6: + count = count + (6 - (length + count)) + return count + +if __name__ == '__main__': + + n = int(input()) + + password = input() + + answer = minimumNumber(n, password) + + print(answer) From d118798b3b0bf5c7c77ad6765ac38fa1b891f24e Mon Sep 17 00:00:00 2001 From: Ronaldd Pinho Date: Wed, 2 Oct 2019 11:38:32 -0300 Subject: [PATCH 014/109] Added Split a String Question --- SplitString/Question.txt | 4 ++++ SplitString/Solution.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 SplitString/Question.txt create mode 100644 SplitString/Solution.cpp diff --git a/SplitString/Question.txt b/SplitString/Question.txt new file mode 100644 index 0000000..07ff26c --- /dev/null +++ b/SplitString/Question.txt @@ -0,0 +1,4 @@ +Given a string, break it into a vector of substrings separated by a specific +character. For example: get the string "name.midname.lastname" and the +character "." as separator, the function should return a list/vector with the +strings {"name", "midname", "lastname"} diff --git a/SplitString/Solution.cpp b/SplitString/Solution.cpp new file mode 100644 index 0000000..3ada9f2 --- /dev/null +++ b/SplitString/Solution.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +using namespace std; + +/** Gets a string and separe through a separator _sep and returns into a + * std::vector */ +std::vector split(std::string _str, char _sep) { + std::vector v; + int begin = 0; + for (int i=0 ; i < _str.size() ; i++){ + if (_str[i] == _sep) { + v.push_back( _str.substr(begin, i-begin) ); + begin = i+1; + } + } + v.push_back(_str.substr(begin, _str.size())); + return v; +}; + + +int main() { + + string str1 = "name.midname.lastname"; + vector vecStr1 = split(str1, '.'); + for (string& s : vecStr1) { + cout << s << endl; + } + + cout << endl; + string str2 = "myname@emailservice.com"; + + vector vecStr2 = split(str2, '@'); + for (string& s : vecStr2) { + cout << s << endl; + } + + return 0; +} \ No newline at end of file From e97bfd95770c9272837bbba8a33a92ed448226dc Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 2 Oct 2019 11:20:56 -0400 Subject: [PATCH 015/109] Added Merge Sort --- Mergesort-JS/mergeSort.js | 33 +++++++++++++++++++++++++++++++++ Mergesort-JS/question.txt | 5 +++++ 2 files changed, 38 insertions(+) create mode 100644 Mergesort-JS/mergeSort.js create mode 100644 Mergesort-JS/question.txt diff --git a/Mergesort-JS/mergeSort.js b/Mergesort-JS/mergeSort.js new file mode 100644 index 0000000..7d8061e --- /dev/null +++ b/Mergesort-JS/mergeSort.js @@ -0,0 +1,33 @@ +const myArray = [2, 4, 1, 6, -7, 8, 5, 9, 3, 4]; + +const mergeSort = (arr) => { + if (arr.length <= 1) { + return arr; + } + + let midIdx = Math.floor(arr.length / 2); + let left = arr.slice(0, midIdx); + let right = arr.slice(midIdx); + + let leftSorted = mergeSort(left); + let rightSorted = mergeSort(right); + + return merge(leftSorted, rightSorted); + +}; + +const merge = (arr1, arr2) => { + let merged = []; + + while (arr1.length && arr2.length) { + if (arr1[0] < arr2[0]) { + merged.push(arr1.shift()); + } else { + merged.push(arr2.shift()); + } + } + + return [...merged, ...arr1, ...arr2]; +}; + +console.log(mergeSort(myArray)); \ No newline at end of file diff --git a/Mergesort-JS/question.txt b/Mergesort-JS/question.txt new file mode 100644 index 0000000..3d3188a --- /dev/null +++ b/Mergesort-JS/question.txt @@ -0,0 +1,5 @@ +Sort the given by implementing Quicksort +[2, 4, 1, 6, -7, 8, 5, 9, 3, 4] + +answer: +[ -7, 1, 2, 3, 4, 4, 5, 6, 8, 9 ] \ No newline at end of file From ce966cd435e67362105001027106982d0263f0c9 Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 2 Oct 2019 11:29:11 -0400 Subject: [PATCH 016/109] Added quicksort-js --- Quicksort-JS/question.txt | 5 +++++ Quicksort-JS/quickSort.js | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 Quicksort-JS/question.txt create mode 100644 Quicksort-JS/quickSort.js diff --git a/Quicksort-JS/question.txt b/Quicksort-JS/question.txt new file mode 100644 index 0000000..3d3188a --- /dev/null +++ b/Quicksort-JS/question.txt @@ -0,0 +1,5 @@ +Sort the given by implementing Quicksort +[2, 4, 1, 6, -7, 8, 5, 9, 3, 4] + +answer: +[ -7, 1, 2, 3, 4, 4, 5, 6, 8, 9 ] \ No newline at end of file diff --git a/Quicksort-JS/quickSort.js b/Quicksort-JS/quickSort.js new file mode 100644 index 0000000..e67e3e7 --- /dev/null +++ b/Quicksort-JS/quickSort.js @@ -0,0 +1,21 @@ +const myArray = [2, 4, 1, 6, -7, 8, 5, 9, 3, 4]; + +const quickSortV1 = arr => { + if (arr.length <= 1) { + return arr; + } + + // shift takes out the element of the array + // so that it can reach the base case + let pivot = arr.shift(); + let left = arr.filter(el => el < pivot); + let right = arr.filter(el => el >= pivot); + + let leftSorted = quickSortV1(left); + let rightSorted = quickSortV1(right); + + return [...leftSorted, pivot, ...rightSorted]; + +}; + +console.log(quickSortV1(myArray)); \ No newline at end of file From 761cc52d2500d12cff1fbecc0a585d3293aa3eb3 Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 2 Oct 2019 11:33:55 -0400 Subject: [PATCH 017/109] Added Powerset --- Powerset/powerset.js | 22 ++++++++++++++++++++++ Powerset/question.txt | 5 +++++ 2 files changed, 27 insertions(+) create mode 100644 Powerset/powerset.js create mode 100644 Powerset/question.txt diff --git a/Powerset/powerset.js b/Powerset/powerset.js new file mode 100644 index 0000000..f6e07b3 --- /dev/null +++ b/Powerset/powerset.js @@ -0,0 +1,22 @@ +// given an array, provide all subsets (powersets); + +// [1,3,2] +// => [[],[1],[2],[3],[1,3],[1,2][2,3],[1,2,3]] + +const powerSet = (arr) => { + const result = []; + + const _recurse = (chosen, remaining) => { + if (remaining.length === 0) { + result.push(chosen); + } else { + _recurse(chosen, remaining.slice(1)); + _recurse(chosen.concat(remaining[0]), remaining.slice(1)); + } + }; + + _recurse([], arr); + return result; +} + +console.log(powerSet([1, 2, 3])); \ No newline at end of file diff --git a/Powerset/question.txt b/Powerset/question.txt new file mode 100644 index 0000000..2eb1aca --- /dev/null +++ b/Powerset/question.txt @@ -0,0 +1,5 @@ +given an array, provide all subsets (powersets); + +result: +[1,3,2] +[[],[1],[2],[3],[1,3],[1,2][2,3],[1,2,3]] \ No newline at end of file From bf7b7071a953f390887622da93b4517582251c66 Mon Sep 17 00:00:00 2001 From: benjamin lopez Date: Wed, 2 Oct 2019 09:39:58 -0600 Subject: [PATCH 018/109] Added Cenit Polar Crypto --- Cenit-Polar-Crypt/Issue.txt | 40 +++++++++++++++++++++++++++++++++++ Cenit-Polar-Crypt/Solution.js | 21 ++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 Cenit-Polar-Crypt/Issue.txt create mode 100644 Cenit-Polar-Crypt/Solution.js diff --git a/Cenit-Polar-Crypt/Issue.txt b/Cenit-Polar-Crypt/Issue.txt new file mode 100644 index 0000000..9014f79 --- /dev/null +++ b/Cenit-Polar-Crypt/Issue.txt @@ -0,0 +1,40 @@ +Create a solution that can be able to encrypt a string using Cenit-Polar Method + +- Solution +Cenit Polar it's a basic scout crytographic method based on replace characters +corresponding this order : +------------------------- +| C | E | N | I | T | +------------------------- +| P | O | L | A | R | +------------------------- + +The main idea is take a word and replace the characters which match in CENIT, with its equivalent on POLAR and viceversa. + +For example, if you want to encrypt the word COMPUTER, you should have to replace any character. +If some character don't have match, you should keep it in place: + +C = P +O = E +M = M +P = C +U = U +T = R +E = O +R = T + +If you want to decript the word generated, you have to do reverse the process, replacing any character which have match in POLAR, +with its equivalent on CENIT : + +P = C +E = O +M = M +C = P +U = U +R = T +O = E +T = R + +Cenit - Polar makes this alphabet table: +A B C D E F G H I J K L M N Ă‘ O P Q R S T U V W X Y Z +I B P D O F G H A J K N M L Ă‘ E C Q T S R U V W X Y Z \ No newline at end of file diff --git a/Cenit-Polar-Crypt/Solution.js b/Cenit-Polar-Crypt/Solution.js new file mode 100644 index 0000000..e5f1bfc --- /dev/null +++ b/Cenit-Polar-Crypt/Solution.js @@ -0,0 +1,21 @@ + +function processWord(encryptedWord){ + let splitedText = (encryptedWord.toLowerCase()).split(""); + let cenit = ["c", "e", "n", "i", "t"]; + var polar = ["p", "o", "l", "a", "r"]; + var encryptWordArray = []; + splitedText.map(function(i) { + if (cenit.indexOf(i) > -1) { + i = polar[cenit.indexOf(i)]; + encryptWordArray.push(i); + } else if (polar.indexOf(i) > -1) { + i = cenit[polar.indexOf(i)]; + encryptWordArray.push(i); + } else { + encryptWordArray.push(i); + } + }); + return encryptWordArray.join("").toUpperCase(); +} + +console.log(processWord("COMPUTER")); \ No newline at end of file From f329067b7cdfc7eee45293857c81ec0d28b79566 Mon Sep 17 00:00:00 2001 From: Piyush Karira Date: Wed, 2 Oct 2019 21:48:04 +0530 Subject: [PATCH 019/109] Added Zero Sum SubArray simple and effective solution --- Zero_Sum_SubArray/question.txt | 4 ++++ Zero_Sum_SubArray/solution.cpp | 37 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 Zero_Sum_SubArray/question.txt create mode 100644 Zero_Sum_SubArray/solution.cpp diff --git a/Zero_Sum_SubArray/question.txt b/Zero_Sum_SubArray/question.txt new file mode 100644 index 0000000..de9d990 --- /dev/null +++ b/Zero_Sum_SubArray/question.txt @@ -0,0 +1,4 @@ +Given an Array of size N, identify whether there exists a subarray with zero sum? + +Conditions: -10^6<=N<=10^6 +Time limit is 1.0 sec diff --git a/Zero_Sum_SubArray/solution.cpp b/Zero_Sum_SubArray/solution.cpp new file mode 100644 index 0000000..793b681 --- /dev/null +++ b/Zero_Sum_SubArray/solution.cpp @@ -0,0 +1,37 @@ +/* C++ Solution */ + +#include +using namespace std; + +/*Function to check whether zero sum subarray exists or not*/ +bool hasZeroSum(int arr[], int N) +{ + set st; + int sum=0; + for(int i=0;i>N; + int arr[N+1]; + + //Array input + for(int i=0;i>arr[i]; + + + bool ans = hasZeroSum(arr,N); + cout< Date: Wed, 2 Oct 2019 12:20:59 -0400 Subject: [PATCH 020/109] Added Leap Year --- Leap Year/instructions.txt | 11 +++++++++++ Leap Year/ruby_solution.rb | 8 ++++++++ 2 files changed, 19 insertions(+) create mode 100644 Leap Year/instructions.txt create mode 100644 Leap Year/ruby_solution.rb diff --git a/Leap Year/instructions.txt b/Leap Year/instructions.txt new file mode 100644 index 0000000..47ee92e --- /dev/null +++ b/Leap Year/instructions.txt @@ -0,0 +1,11 @@ +Leap +Given a year, report if it is a leap year. + +The tricky thing here is that a leap year in the Gregorian calendar occurs: + +on every year that is evenly divisible by 4 + except every year that is evenly divisible by 100 + unless the year is also evenly divisible by 400 +For example, 1997 is not a leap year, but 1996 is. 1900 is not a leap year, but 2000 is. + +If your language provides a method in the standard library that does this look-up, pretend it doesn't exist and implement it yourself. diff --git a/Leap Year/ruby_solution.rb b/Leap Year/ruby_solution.rb new file mode 100644 index 0000000..d5051d8 --- /dev/null +++ b/Leap Year/ruby_solution.rb @@ -0,0 +1,8 @@ +def leap(year) + puts year %400 == 0 || year %4 == 0 && !(year %100 == 0) +end + +leap(1996) #expect true +leap(2000) #expect true +leap(2015) #expect false +leap(1800) #expect false From 6f93310ece3d1b9696d0879d14f20b80418ef350 Mon Sep 17 00:00:00 2001 From: Alberto Sobrinho Date: Wed, 2 Oct 2019 13:44:45 -0300 Subject: [PATCH 021/109] isograms --- Isograms/isograms.py | 12 ++++++++++++ Isograms/problem_statement.txt | 7 +++++++ 2 files changed, 19 insertions(+) create mode 100644 Isograms/isograms.py create mode 100644 Isograms/problem_statement.txt diff --git a/Isograms/isograms.py b/Isograms/isograms.py new file mode 100644 index 0000000..453f09f --- /dev/null +++ b/Isograms/isograms.py @@ -0,0 +1,12 @@ +def is_isogram(string): + lower_string = string.lower() + unique_string = set(lower_string) + return (len(lower_string)==len(unique_string)) + +def main(): + print(is_isogram("Dermatoglyphics")) + print(is_isogram("aba")) + print(is_isogram("moOse")) + print(is_isogram("")) + +main() \ No newline at end of file diff --git a/Isograms/problem_statement.txt b/Isograms/problem_statement.txt new file mode 100644 index 0000000..60d5e8a --- /dev/null +++ b/Isograms/problem_statement.txt @@ -0,0 +1,7 @@ +An isogram is a word that has no repeating letters, consecutive or non-consecutive. +How to determine whether a string is an isogram. Ignore letter case + +Ex. +"Dermatoglyphics" is isogram. +"aba" is not isogram. +"moOse" is not isogram. \ No newline at end of file From e2450ccd6654f50a4737868b1a38c184a52f0ccf Mon Sep 17 00:00:00 2001 From: Piyush Karira Date: Thu, 3 Oct 2019 01:03:11 +0530 Subject: [PATCH 022/109] Merging 2 sorted array --- Merging_Two_Sorted_Array/question.txt | 1 + Merging_Two_Sorted_Array/solution.cpp | 54 +++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 Merging_Two_Sorted_Array/question.txt create mode 100644 Merging_Two_Sorted_Array/solution.cpp diff --git a/Merging_Two_Sorted_Array/question.txt b/Merging_Two_Sorted_Array/question.txt new file mode 100644 index 0000000..43fe95f --- /dev/null +++ b/Merging_Two_Sorted_Array/question.txt @@ -0,0 +1 @@ +Given two sorted arrays arr1[] and arr2[] in non-decreasing order with size n and m. The task is to merge the two sorted arrays into one sorted array (in non-decreasing order) diff --git a/Merging_Two_Sorted_Array/solution.cpp b/Merging_Two_Sorted_Array/solution.cpp new file mode 100644 index 0000000..a61ab49 --- /dev/null +++ b/Merging_Two_Sorted_Array/solution.cpp @@ -0,0 +1,54 @@ +#include +using namespace std; +int main() + { + int t; + cin>>t; + while(t--) + { + int x,y; + cin>>x>>y; + long a[x+1],b[y+1]; + for(int i=0;i>a[i]; + for(int i=0;i>b[i]; + + int i=0,j=0; + vector vec; + while(ib[j]) + { + vec.push_back(b[j]); + j++; + } + else if(a[i]==b[j]) + { + vec.push_back(a[i]); + vec.push_back(b[j]); + i++; + j++; + } + } + while(i Date: Thu, 3 Oct 2019 02:52:20 +0530 Subject: [PATCH 023/109] Added spiralMatrix problem for C++ --- SpiralMatrix/problem.txt | 21 +++++++++++++++++++ SpiralMatrix/solution.cpp | 43 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 SpiralMatrix/problem.txt create mode 100644 SpiralMatrix/solution.cpp diff --git a/SpiralMatrix/problem.txt b/SpiralMatrix/problem.txt new file mode 100644 index 0000000..8f5bbe4 --- /dev/null +++ b/SpiralMatrix/problem.txt @@ -0,0 +1,21 @@ +Given a 2D array, print it in spiral form. See the following examples. + +Examples: + +Input: + 1 2 3 4 + 5 6 7 8 + 9 10 11 12 + 13 14 15 16 + +Output: +1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10 + + +Input: + 1 2 3 4 5 6 + 7 8 9 10 11 12 + 13 14 15 16 17 18 + +Output: +1 2 3 4 5 6 12 18 17 16 15 14 13 7 8 9 10 11 \ No newline at end of file diff --git a/SpiralMatrix/solution.cpp b/SpiralMatrix/solution.cpp new file mode 100644 index 0000000..92b45a2 --- /dev/null +++ b/SpiralMatrix/solution.cpp @@ -0,0 +1,43 @@ +#include +using namespace std; +#define R 3 +#define C 6 + +void spiralPrint(int m, int n, int a[R][C]) +{ + int i, k = 0, l = 0; + + while (k < m && l < n) + { + for (i = l; i < n; ++i) + cout << a[k][i] << " "; + k++; + + for (i = k; i < m; ++i) + cout << a[i][n - 1] << " "; + n--; + + if (k < m) + { + for (i = n - 1; i >= l; --i) + cout << a[m - 1][i] << " "; + m--; + } + + if (l < n) { + for (i = m - 1; i >= k; --i) + cout << a[i][l] << " "; + l++; + } + } +} + +int main() +{ + int a[R][C] = { { 1, 2, 3, 4, 5, 6 }, + { 7, 8, 9, 10, 11, 12 }, + { 13, 14, 15, 16, 17, 18 } }; + + spiralPrint(R, C, a); + return 0; +} \ No newline at end of file From 17dbf722e9112941e575ef0ffd1e44259ed5dee4 Mon Sep 17 00:00:00 2001 From: jonathan-sh Date: Wed, 2 Oct 2019 21:46:32 -0300 Subject: [PATCH 024/109] added question: IS PRIME? --- Is prime?/problem.txt | 9 +++++++++ Is prime?/solution.hs | 1 + 2 files changed, 10 insertions(+) create mode 100644 Is prime?/problem.txt create mode 100644 Is prime?/solution.hs diff --git a/Is prime?/problem.txt b/Is prime?/problem.txt new file mode 100644 index 0000000..7357bc2 --- /dev/null +++ b/Is prime?/problem.txt @@ -0,0 +1,9 @@ +Implement a function that determines if a given positive integer is a prime or not. + +Example + +For n = 47, the output should be +isPrime(n) = true; + +For n = 4, the output should be +isPrime(n) = false; \ No newline at end of file diff --git a/Is prime?/solution.hs b/Is prime?/solution.hs new file mode 100644 index 0000000..05b33bc --- /dev/null +++ b/Is prime?/solution.hs @@ -0,0 +1 @@ +isPrime n = length (filter (==0) (map (mod n) [1..n])) == 2 \ No newline at end of file From f7d240235f2351565d40cb0bd59c2fbf7c744e8c Mon Sep 17 00:00:00 2001 From: Akos Kovacs Date: Thu, 3 Oct 2019 08:41:58 +0200 Subject: [PATCH 025/109] Create question.txt --- Reverse string in place/question.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Reverse string in place/question.txt diff --git a/Reverse string in place/question.txt b/Reverse string in place/question.txt new file mode 100644 index 0000000..bce9195 --- /dev/null +++ b/Reverse string in place/question.txt @@ -0,0 +1,2 @@ +Write a program to reverse a String in place in Java, without using additional memory. +You cannot use any library classes or methods like e.g. StringBuilder to solve this problem. This restriction is placed because StringBuilder and StringBuffer class define a reverse() method which can easily reverse the given String. From 969af667daca72949a1577ebf86d902368ca6d3d Mon Sep 17 00:00:00 2001 From: Akos Kovacs Date: Thu, 3 Oct 2019 08:43:17 +0200 Subject: [PATCH 026/109] Added solution for Reverse string in place --- Reverse string in place/solution.java | 74 +++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 Reverse string in place/solution.java diff --git a/Reverse string in place/solution.java b/Reverse string in place/solution.java new file mode 100644 index 0000000..21999cc --- /dev/null +++ b/Reverse string in place/solution.java @@ -0,0 +1,74 @@ +import org.junit.Assert; +import org.junit.Test; + +/** + * Java Program to reverse a String in place, + * without any additional buffer in Java. + * + * @author WINDOWS 8 + * + */ +public class StringReversal { + + /** + * Java method to reverse a String in place + * @param str + * @return reverse of String + */ + public static String reverse(String str) { + if(str == null || str.isEmpty()){ + return str; + } + char[] characters = str.toCharArray(); + int i = 0; + int j = characters.length - 1; + while (i < j) { + swap(characters, i, j); + i++; + j--; + } + return new String(characters); + } + + /** + * Java method to swap two numbers in given array + * @param str + * @param i + * @param j + */ + private static void swap(char[] str, int i, int j) { + char temp = str[i]; + str[i] = str[j]; + str[j] = temp; + } + + @Test + public void reverseEmptyString(){ + Assert.assertEquals("", reverse("")); + } + + @Test + public void reverseString(){ + Assert.assertEquals("cba", reverse("abc")); + } + + @Test + public void reverseNullString(){ + Assert.assertEquals(null, reverse(null)); + } + + @Test + public void reversePalindromeString(){ + Assert.assertEquals("aba", reverse("aba")); + } + + @Test + public void reverseSameCharacterString(){ + Assert.assertEquals("aaa", reverse("aaa")); + } + + @Test + public void reverseAnagramString(){ + Assert.assertEquals("mary", reverse("yram")); + } +} From a1fab7aac89178bc12636f5bd92539052490e21b Mon Sep 17 00:00:00 2001 From: Akos Kovacs Date: Thu, 3 Oct 2019 08:48:10 +0200 Subject: [PATCH 027/109] Rod cutting problem added --- Rod cutting problem/question.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 Rod cutting problem/question.txt diff --git a/Rod cutting problem/question.txt b/Rod cutting problem/question.txt new file mode 100644 index 0000000..97e5488 --- /dev/null +++ b/Rod cutting problem/question.txt @@ -0,0 +1 @@ +Given a rod of length n, and an array that contains the prices of all the pieces smaller than n, determine the maximum profit you could obtain from cutting up the rod and selling its pieces. From 30a066a702c4b5c614eb9c61521ac98173fd61a5 Mon Sep 17 00:00:00 2001 From: Akos Kovacs Date: Thu, 3 Oct 2019 08:49:43 +0200 Subject: [PATCH 028/109] Solution of Rod cutting problem added --- Rod cutting problem/solution.java | 51 +++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Rod cutting problem/solution.java diff --git a/Rod cutting problem/solution.java b/Rod cutting problem/solution.java new file mode 100644 index 0000000..9f31281 --- /dev/null +++ b/Rod cutting problem/solution.java @@ -0,0 +1,51 @@ +class rod_cutting +{ + static int cut_rod(int price[], int n) + { + // Declaring a 2D array, T + int T[][] = new int[n-1][n+1]; + + // Initializing the array to all zeros + for(int i=0; i < n-1; i++) + { + for(int j=0; j < n+1; j++ ) + { + T[i][j] = 0; + } + } + + for(int i=0; i < n-1; i++) + { + for(int j=0; j < n+1; j++ ) + { + // First column => 0 length of rod => 0 profit + if(j == 0) { + continue; + } + + // First row => T[i-1][j] doesn't exist so just pick the second value + else if(i == 0) { + T[i][j] = price[i] + T[i][j-i-1]; + } + + // where j <= i => T[i][j-i-1] doesn't exist so just pick the first value + else if(j-i-1 < 0) { + T[i][j] = T[i-1][j]; + } + + // using the whole expression + else { + T[i][j] = Math.max(T[i-1][j], (price[i] + T[i][j-i-1])); + } + } + } + return T[n-2][n]; + } + + public static void main(String args[]) + { + int price[] = new int[] {2,5,7,8}; + int n = 5; + System.out.println("Maximum profit is " + cut_rod(price, n)); + } +} From 2e562d972b44f8f4d410b0d1cc89e8c969e21d74 Mon Sep 17 00:00:00 2001 From: arc9693 Date: Thu, 3 Oct 2019 18:20:17 +0530 Subject: [PATCH 029/109] Added binary search solution in c++ --- binary_search/solution.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 binary_search/solution.cpp diff --git a/binary_search/solution.cpp b/binary_search/solution.cpp new file mode 100644 index 0000000..09ecfb5 --- /dev/null +++ b/binary_search/solution.cpp @@ -0,0 +1,32 @@ +#include +#include +using namespace std; + +bool binarySearch(vector arr,int ele) +{ + int l=0; + int r=arr.size()-1; + while(l<=r) + { + int m=(l+r)/2; + if(arr[m]==ele) + return true; + else{ + if(arr[m] arr({1,2,3,4,5}); + int ele=1; + if(binarySearch(arr,ele)) + cout<<"Exists"< Date: Thu, 3 Oct 2019 18:23:43 +0530 Subject: [PATCH 030/109] Added BS solution in python --- binary_search/solution.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 binary_search/solution.py diff --git a/binary_search/solution.py b/binary_search/solution.py new file mode 100644 index 0000000..4398fdd --- /dev/null +++ b/binary_search/solution.py @@ -0,0 +1,22 @@ +def binarySearch(arr,ele): + l=0 + r=len(arr)-1 + while(l<=r): + m=(l+r)//2 + if(arr[m]==ele): + return True + else: + if(arr[m] Date: Thu, 3 Oct 2019 18:27:21 +0530 Subject: [PATCH 031/109] Added c++ solution of kadane's algo --- Kadane's Algorithm/kadane.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Kadane's Algorithm/kadane.cpp diff --git a/Kadane's Algorithm/kadane.cpp b/Kadane's Algorithm/kadane.cpp new file mode 100644 index 0000000..0101507 --- /dev/null +++ b/Kadane's Algorithm/kadane.cpp @@ -0,0 +1,27 @@ +#include +#include +using namespace std; + +int maxSubarraySum(vector a, int l) { + int max = INT_MIN, max_here = 0; + + for (int i = 0; i < l; i++) { + max_here = max_here + a[i]; + if (max < max_here) max = max_here; + if (max_here < 0) max_here = 0; + } + + return max; +} + + +int main() { + vector arr({-2, -3, 4, -1, -2, 1, 5, -3}); + int l = arr.size(); + + int m = maxSubarraySum(arr, l); + + cout< Date: Thu, 3 Oct 2019 18:34:25 +0530 Subject: [PATCH 032/109] Added python sol of kadane's algo --- Kadane's Algorithm/kadane.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Kadane's Algorithm/kadane.py diff --git a/Kadane's Algorithm/kadane.py b/Kadane's Algorithm/kadane.py new file mode 100644 index 0000000..1c8ceea --- /dev/null +++ b/Kadane's Algorithm/kadane.py @@ -0,0 +1,21 @@ +def maxSubarraySum(a, l): + _max = -999999 + max_here = 0 + for i in range(l): + max_here = max_here + a[i] + if (_max < max_here): + _max = max_here + if (max_here < 0): + max_here = 0 + + + return _max + + +if __name__ == '__main__': + arr=[-2, -3, 4, -1, -2, 1, 5, -3] + l=len(arr) + m = maxSubarraySum(arr, l) + print(m," is the max subarray sum") + + From c77ae740416dc3a169de654ccd258c670cd4f81b Mon Sep 17 00:00:00 2001 From: arc9693 Date: Thu, 3 Oct 2019 18:35:58 +0530 Subject: [PATCH 033/109] Add python implementation of floodfill --- Floodfill/solution.py | 54 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Floodfill/solution.py diff --git a/Floodfill/solution.py b/Floodfill/solution.py new file mode 100644 index 0000000..319d3f7 --- /dev/null +++ b/Floodfill/solution.py @@ -0,0 +1,54 @@ +# Python3 program to implement +# flood fill algorithm + +# Dimentions of paint screen +M = 8 +N = 8 + +# A recursive function to replace +# previous color 'prevC' at '(x, y)' +# and all surrounding pixels of (x, y) +# with new color 'newC' and +def floodFillUtil(screen, x, y, prevC, newC): + + # Base cases + if (x < 0 or x >= M or y < 0 or + y >= N or screen[x][y] != prevC or + screen[x][y] == newC): + return + + # Replace the color at (x, y) + screen[x][y] = newC + + # Recur for north, east, south and west + floodFillUtil(screen, x + 1, y, prevC, newC) + floodFillUtil(screen, x - 1, y, prevC, newC) + floodFillUtil(screen, x, y + 1, prevC, newC) + floodFillUtil(screen, x, y - 1, prevC, newC) + +# It mainly finds the previous color on (x, y) and +# calls floodFillUtil() +def floodFill(screen, x, y, newC): + prevC = screen[x][y] + floodFillUtil(screen, x, y, prevC, newC) + +# Driver Code +screen = [[1, 1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 0, 0], + [1, 0, 0, 1, 1, 0, 1, 1], + [1, 2, 2, 2, 2, 0, 1, 0], + [1, 1, 1, 2, 2, 0, 1, 0], + [1, 1, 1, 2, 2, 2, 2, 0], + [1, 1, 1, 1, 1, 2, 1, 1], + [1, 1, 1, 1, 1, 2, 2, 1]] + +x = 4 +y = 4 +newC = 3 +floodFill(screen, x, y, newC) + +print ("Updated screen after call to floodFill:") +for i in range(M): + for j in range(N): + print(screen[i][j], end = ' ') + print() From 4031662cdd860ab3be75eb5ebac55a5307e31644 Mon Sep 17 00:00:00 2001 From: luminousbeam Date: Thu, 3 Oct 2019 15:00:38 -0400 Subject: [PATCH 034/109] Added Acronym problem --- Acronym/instructions.txt | 6 ++++++ Acronym/ruby_solution.rb | 13 +++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 Acronym/instructions.txt create mode 100644 Acronym/ruby_solution.rb diff --git a/Acronym/instructions.txt b/Acronym/instructions.txt new file mode 100644 index 0000000..f4f3cf7 --- /dev/null +++ b/Acronym/instructions.txt @@ -0,0 +1,6 @@ +Acronym +Convert a phrase to its acronym. + +Techies love their TLA (Three Letter Acronyms)! + +Help generate some jargon by writing a program that converts a long name like Portable Network Graphics to its acronym (PNG). diff --git a/Acronym/ruby_solution.rb b/Acronym/ruby_solution.rb new file mode 100644 index 0000000..346c592 --- /dev/null +++ b/Acronym/ruby_solution.rb @@ -0,0 +1,13 @@ +def abbreviate(string) + string_arr = string.scan(/\b\w/) + string_arr.join.upcase +end + + +# begin +# >> abbreviate("Portable Network Graphics") +# => "PNG" +# >> abbreviate("Ruby on Rails") +# => "ROR" +# >> abbreviate("GNU Image Manipulation Program") +# => "GIMP" From 6da99721c0d60462f9746e3edc43e258a75bf78a Mon Sep 17 00:00:00 2001 From: Muskan Goyal Date: Fri, 4 Oct 2019 00:34:38 +0530 Subject: [PATCH 035/109] adding nqueen problem --- nQueen/Question.txt | 10 +++++ nQueen/nQueen.cpp | 90 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 nQueen/Question.txt create mode 100755 nQueen/nQueen.cpp diff --git a/nQueen/Question.txt b/nQueen/Question.txt new file mode 100644 index 0000000..8e50ad1 --- /dev/null +++ b/nQueen/Question.txt @@ -0,0 +1,10 @@ +The N Queen is the problem of placing N chess queens on an NĂ—N chessboard so +that no two queens attack each other. For example, following is a solution +for 4 Queen problem. +The expected output is a binary matrix which has Qs for the blocks where +queens are placed and Xs where queens are not placed. +EXAMPLE: +X X Q X +Q X X X +X X X Q +X Q X X \ No newline at end of file diff --git a/nQueen/nQueen.cpp b/nQueen/nQueen.cpp new file mode 100755 index 0000000..0cfd39c --- /dev/null +++ b/nQueen/nQueen.cpp @@ -0,0 +1,90 @@ + +#include +using namespace std; + +char board[30][30]; + +void printBoard(char arr[][30], int n) { + for (int r = 0; r < n; ++r) { + for (int c = 0; c < n; ++c) { + cout << arr[r][c] << " " ; + } + cout << endl; + } +} + +void initialiseBoard(int n) { + for (int r = 0; r < n; ++r) { + for (int c = 0; c < n; ++c) { + board[r][c] = 'X'; + } + } +} + +bool canPlace(char board[][30], int N, int x, int y) +{ + //check the row if aqueen already exists + for (int r = 0; r < N; ++r) + { + if (board[r][y] == 'Q') + return false; + } + + int rInc[] = { -1, +1, +1, -1}; + int cInc[] = { -1, +1, -1, +1}; + //check diagonal if queen already exists + for (int dir = 0; dir < 4; ++dir) + { + int rowAdd = rInc[dir]; + int colAdd = cInc[dir]; + int r = x + rowAdd; + int c = y + colAdd; + //check that r c is within the board + while (r >= 0 && r < N && c >= 0 && c < N) + { + if (board[r][c] == 'Q') + return false; + r = r + rowAdd; + c = c + colAdd; + } + } + return true; +} + +bool nqueen(int r, int n) +{ + if (r == n)//base case if all queens are placed + { + return true; + } + //for every column, use hit and trial by placing a queen in the each cell of curr Row + for (int c = 0; c < n; ++c) + { + int x = r; + int y = c; + //check if queen can be placed on board[i][c] + if (canPlace(board, n, x, y)==true) + { + board[x][y] = 'Q'; //place queen in each column + bool isSuccessful = nqueen(r + 1, n); //recursion to place rest of queens + if (isSuccessful == true) + return true; + board[x][y] = 'X'; //else unmark the cell or backtrack + } + } + return false; //if queen cannot be placed in any row in this column then return false +} + +int main() +{ + int n; + cin >> n; + + initialiseBoard(n);//initialse all the board with X + bool isSuccessful = nqueen(0, n); + + if (isSuccessful) printBoard(board, n); + else cout << "Sorry man! You need to have a larger board!\n"; + + return 0; +} From 73165f010401f66dad482e304b78b3d0bc0fb2f4 Mon Sep 17 00:00:00 2001 From: Chipp Chirp <32373017+chippyho123@users.noreply.github.com> Date: Thu, 3 Oct 2019 15:08:52 -0400 Subject: [PATCH 036/109] Added Problem answer in .java --- The Additionator/The Additionator.txt | 20 ++++++++++++++++++++ The Additionator/solution.java | 14 ++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 The Additionator/The Additionator.txt create mode 100644 The Additionator/solution.java diff --git a/The Additionator/The Additionator.txt b/The Additionator/The Additionator.txt new file mode 100644 index 0000000..59a741e --- /dev/null +++ b/The Additionator/The Additionator.txt @@ -0,0 +1,20 @@ +The Additionator - + +The first line contains an integer 1≤N≤100000 (The number of addition problems). The next N lines will each contain two space-separated integers whose absolute value is less than 1000000000 (numbers to add) + +Output N lines of one integer each, the solutions to the addition problems in order. + +Example: + +IN + +3 +4 2 +-1 -1000 +9 10 + +OUT + +6 +-1001 +19 diff --git a/The Additionator/solution.java b/The Additionator/solution.java new file mode 100644 index 0000000..d5a160f --- /dev/null +++ b/The Additionator/solution.java @@ -0,0 +1,14 @@ +import java.util.*; + +public class Main { + public static void main(String[] args) { + Scanner in = new Scanner(System.in); + + int N = in.nextInt(); + for (int i = 0; i < N; i++) { + int a = in.nextInt(); + int b = in.nextInt(); + System.out.println(a + b); + } + } +} From 5b15ea4fef6b4770212374ad5772fddaeca44d95 Mon Sep 17 00:00:00 2001 From: Muskan Goyal Date: Fri, 4 Oct 2019 01:24:31 +0530 Subject: [PATCH 037/109] add merge sort --- .DS_Store | Bin 0 -> 12292 bytes Mersort_In_C++/mergeSort.cpp | 78 +++++++++++++++++++++++++++++++++++ Mersort_In_C++/mergesort.txt | 13 ++++++ 3 files changed, 91 insertions(+) create mode 100644 .DS_Store create mode 100755 Mersort_In_C++/mergeSort.cpp create mode 100644 Mersort_In_C++/mergesort.txt diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..bfd6c0b87bb54e5cbd8f2d022fe4d95e07f6f98c GIT binary patch literal 12292 zcmeI2%W_*q5QbZhNn|j=aT3g}io=Q&DNz_w#e$-+W1A2HalqU+Mz$4Mi6yygDHm4R zP`m-fo)yJYunQY_4fZ?$e1FfeGBdtVVZnkNsm__v(ft3+^z`&}w`69ui^GjsvvX!v z=TbQ}$?ZF{;t9&=rSEm^dmZCRjq4g0^(nIrYg*4*_Ok8nYrX%$7>|S>=bE-FU}Jn? z^R{Je>)VcXY+#$#y}Z?5U)$=h(Vou6p9Nn3%U?V(I|HK4dxsJ1^6uCzYK1MpahuPD zt=Km88{%<9b*m&$NuZKIC4ou;kDdf{_VTJ{=Y4ou-75)H5_qH~Ap1~oshlgzd!cmG z!A&l_zLyK{FY37F{;Vj=xw5<$N{51RC}n`w$`GR#;5;wXoN}%#?}akJtrp-`D|@b$ z5lYQ_2UmD=tIdV7x>pjYB(PrsukmQYJ|IqR5*ruxrPp?{NSmxc5@|mLqC<3k*CYMH z-Xp5+g1qg~`ppz=Z-KrO#pzS_A-%O>Sht49&m%!$+x%#%{*+XU6ng#?)XOEk>ddw!o|2uuuGn@-A&;*h)Fa zni=OLoWixa@A_&D;CMfm`PlCn?wJv;<2|j?uU1=9R)$8S+2GSW^#i1R?Cp&2WXZQT zhE=-^uU7KBoloa*?0e3cUnBiF61&x&U0LsUwc5?z`C#$KU*^I7 z17_o)G25FDH?CVNJH4%bugzF$Ty?vOgxBpRYuu#F*7?}anS75U&5zK#7VlmrPu61W zek9K+TW0Mx&`qsmVN0Gj>ruNzU+7wj_q2{^blP#XFWB=CuTUnbSZM3(QeZ)#|*M3koQkHcyl|oHcBkp^KHnK4{O7tq_ z(7ClD;kz~e+_hPIJ!6yQh}kB6?PXtY9=Xe#8E)!8+&1&n-21sExs{0fov@G5o_Skj zcQ4ti=*~tuQnv#!Vg^LZ^)0NbtmObn1S?Z`sretS^)cHxY|Ge?D`~H;v2nZ8w9`5l zNN7lZrKaYR&RC?mG0T(KzDxEgt1PY5dP@)9unTq}Md}0``y$fir$Opu*K&q+670eBYEbGA{Hy;W`UfhqfWt9nP2~*SZ1RlBRl6Rz5#(H~|x;Ntm`>gQej* zqr*zvNk<^vO>j>*ZVTjq+GzDM6grxqBt5m2jd$&v$|W{=8#=@*0GzZ{^m3HBwF!cFJ zv-f<6au27nk@Ze`I63M;o<}(EkFdrGc6x+Ocb2sMbH*v1%Vs!^W+xmoB}eeAv=>#| z^x4UCkj!PR4xEi^`~67UHJd%l-Jo_I?S9X>`qoJ$AuFDoO?9vzv&WXODf85p()P09 zN&6GbaURS9J-lldv)0nwcw}d39d<{-YW0!OfN|YqhK2iBvghku?4FEC+8i^Tvadi% zCJ($)d8ccKc|@+&F~e~fmeHUE5TB*J$<8LdMb1rCtt3!MppwA9l)#JN&e&^M97q^uXsPo{Yo&8%2{@PuJ1V~`};a1OX16nEmK zB>2a{<3Z44!~IspX_=4fI{HJTqmMDiB`YMaTq}Ru>zhd{`RR&kl#6DJnFQDwiM(F$ z45RW3Bl`?C#LJRM;m>!OLzZtzd9_;--U)cMx0Is^k=i>MLb=p<_H{?}SwEdHoO5Y= z&ymFKr^(MMlGiQ{7FYkTJMwJyeBc8PNqE0)dKW|jsDhX5)_ +using namespace std; + +void copyArr(int from[], int si, int ei, int * to) { + // while (si <= ei) *to++ = *si++; + while (si <= ei) { + *to = from[si]; + ++si; + ++to; + } +} + + +void mergeSortedArray(int arr[], int si, int ei, int mid) { + + int tmp_A[100]; + int tmp_B[100]; + + copyArr(arr, si, mid, tmp_A); + copyArr(arr, mid + 1, ei, tmp_B); + + int i = 0; + int j = 0; + int k = si; + + //while a has elements and b has elements, I have to do something + int size_A = mid - si + 1; + int size_B = ei - (mid + 1) + 1; + + while (i < size_A && j < size_B) { + if (tmp_A[i] < tmp_B[j]) { + arr[k] = tmp_A[i]; + i++; + k++; + } + else { + arr[k++] = tmp_B[j++]; + } + } + + while (i < size_A) { + arr[k++] = tmp_A[i++]; + } + + while (j < size_B) arr[k++] = tmp_B[j++]; + + +} + + +void mergeSort(int arr[], int si, int ei) { + if (si >= ei) { + //no elements + return; + } + + int mid = (si + ei) / 2; + //sort the left part + mergeSort(arr, si, mid); + mergeSort(arr, mid + 1, ei); + + mergeSortedArray(arr, si, ei, mid); + +} + + +int main() { + int arr[100]; + int n; + cin >> n; + inputArr(arr, n); + + mergeSort(arr, 0, n - 1); + + printArr(arr, n); +} diff --git a/Mersort_In_C++/mergesort.txt b/Mersort_In_C++/mergesort.txt new file mode 100644 index 0000000..ba3cfe6 --- /dev/null +++ b/Mersort_In_C++/mergesort.txt @@ -0,0 +1,13 @@ +Merge Sort is a Divide and Conquer algorithm. It divides input array in +two halves, calls itself for the two halves and then merges the two sorted halves. +Algorithm: +MergeSort(arr[], l, r) +If r > l +1. Find the middle point to divide the array into two halves: + middle m = (l+r)/2 +2. Call mergeSort for first half: + Call mergeSort(arr, l, m) +3. Call mergeSort for second half: + Call mergeSort(arr, m+1, r) +4. Merge the two halves sorted in step 2 and 3: + Call merge(arr, l, m, r) \ No newline at end of file From 28ed88b004c87a30e75547473c93100a78f0a3ff Mon Sep 17 00:00:00 2001 From: Muskan Goyal Date: Fri, 4 Oct 2019 01:37:52 +0530 Subject: [PATCH 038/109] subsequences --- .DS_Store | Bin 12292 -> 12292 bytes Subsequences/question.txt | 6 ++++++ Subsequences/subsequences.cpp | 27 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 Subsequences/question.txt create mode 100755 Subsequences/subsequences.cpp diff --git a/.DS_Store b/.DS_Store index bfd6c0b87bb54e5cbd8f2d022fe4d95e07f6f98c..fa501d182026124fbe10cdd77cce43730721611a 100644 GIT binary patch delta 309 zcmZokXi1ph<8bU^hRb*=8OAW6pXWhG2$Lh9rh!hE#?^AS;z2k0BXI7JKI8Cnx3P zCowQE2rw`({RZOl|4;xF!>KPP-7q*gKeqs=1_p4d&CRcOae-RGvANRdoa^F)jzC>_ nG^CKEz955uW5khsTozoEmy@5D4s-zHW*f=vted$Ne)0nVz@AM= delta 34 qcmZokXi1ph&ls>VU^hRb!Db!-W6sUtQd?LzD= +using namespace std; +char output[100] = ""; + +void printSubSeq(char str[], int be, int idx) +{ + if (str[be] == '\0') + { + output[idx] = '\0'; + cout << output << endl; + return; + } + + printSubSeq(str, be + 1, idx); + output[idx] = str[be]; + printSubSeq(str, be + 1, idx + 1); +} + + +int main() { + char str[100]; + cin >> str; + + + printSubSeq(str, 0, 0); +} From fa0fe8b5804470491ed221f7790bf274cb2d4084 Mon Sep 17 00:00:00 2001 From: JanviMahajan14 Date: Fri, 4 Oct 2019 03:12:50 +0530 Subject: [PATCH 039/109] Added PROXY problem --- PROXY/question.txt | 33 +++++++++++++++++++++++++++++++ PROXY/solution.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 PROXY/question.txt create mode 100644 PROXY/solution.cpp diff --git a/PROXY/question.txt b/PROXY/question.txt new file mode 100644 index 0000000..aeecadd --- /dev/null +++ b/PROXY/question.txt @@ -0,0 +1,33 @@ +Chef is a brilliant university student that does not attend lectures because he believes that they are boring and coding is life! However, his university follows certain rules and regulations, and a student may only take an exam for a course if he has attended at least 75% of lectures for this course. + +Since you are Chef's best friend, you want to help him reach the attendance he needs to take exams. Unfortunately, Chef is still focused on his code and refuses to attend more lectures, so the only option is to have some of his friends mark him as present by proxy. This trick is well-known in the university, but only few have the talent to pull it off. + +In a certain course, there is exactly one lesson per day over the course of D days (numbered 1 through D). You are given a string S with length D describing the lessons Chef attended — for each valid i, the i-th character of this string is either 'A' if Chef was absent on day i or 'P' if Chef was actually present on day i. + +For each day d when Chef is absent, one of Chef's friends can mark him as present by proxy on this day only if he was present (if he was really present, not just marked as present) on at least one of the previous two days, i.e. days dâ’1 and dâ’2, and on at least one of the following two days, i.e. days d+1 and d+2. However, it is impossible to mark him as present by proxy on the first two days and the last two days. + +Find the minimum number of times Chef has to be marked as present by proxy so that his attendance becomes at least 75% (0.75). Chef's attendance is number of days when he was marked as present, either by proxy or by actually being present, divided by D. + +Input +The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. +The first line of each test case contains a single integer D. +The second line contains a single string S with length D. + +Output +For each test case, print a single line containing one integer — the minimum number of times Chef needs to be marked as present by proxy, or â’1 if it is impossible to make Chef achieve 75% attendance. + +Constraints +1≤T≤200 +1≤D≤1,000 +S contains only characters 'A' and 'P' +Subtasks +Subtask #1 (100 points): original constraints + +Example Input +1 +9 +PAAPPAPPP +Example Output +1 +Explanation +Example case 1: With a proxy on the third day, the attendance string is "PAPPPAPPP". Now, Chef's attendance is at least 75%, so the minimum number of times Chef needs to be marked as present by proxy is 1. \ No newline at end of file diff --git a/PROXY/solution.cpp b/PROXY/solution.cpp new file mode 100644 index 0000000..9eb5c92 --- /dev/null +++ b/PROXY/solution.cpp @@ -0,0 +1,49 @@ +#include +using namespace std; + +float att(int act,int cnt,int d){ + float t = (double)cnt/d; + if(t>=0.75) + cout<>t; + while(t--){ + int d,cnt=0,i=0,flag=0; + cin>>d; + char s[d]; + cin >> s; + + + //count of present + for(i=0;i=0.75){ + flag=1; + break; + } + + } + } + if(flag==0) + cout<<-1< Date: Fri, 4 Oct 2019 08:20:11 +0800 Subject: [PATCH 040/109] Added Least Common Multiple --- Least_Common_Multiple/Problem.txt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Least_Common_Multiple/Problem.txt diff --git a/Least_Common_Multiple/Problem.txt b/Least_Common_Multiple/Problem.txt new file mode 100644 index 0000000..83e009c --- /dev/null +++ b/Least_Common_Multiple/Problem.txt @@ -0,0 +1,6 @@ +## Problem: + +The LCM of two integers n1 and n2 is the smallest positive integer that is perfectly +divisible by both n1 and n2 (without a remainder). For example: the LCM of 72 and 120 is 360. + +write a program written in COBOL that will compute the LCM of 2 numbers From ded766048dfe3fa96fa8a2832b70dfabdbc203bc Mon Sep 17 00:00:00 2001 From: Earl Austin Avila Zuniga Date: Fri, 4 Oct 2019 08:20:53 +0800 Subject: [PATCH 041/109] Added Least Common Multiple --- Least_Common_Multiple/LCM.cbl | 78 +++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 Least_Common_Multiple/LCM.cbl diff --git a/Least_Common_Multiple/LCM.cbl b/Least_Common_Multiple/LCM.cbl new file mode 100644 index 0000000..ab35774 --- /dev/null +++ b/Least_Common_Multiple/LCM.cbl @@ -0,0 +1,78 @@ + IDENTIFICATION DIVISION. + + PROGRAM-ID.LCM. + + ENVIRONMENT DIVISION. + + DATA DIVISION. + + WORKING-STORAGE SECTION. + + 01 ARRAY. + 02 A PIC 9(5) OCCURS 10 TIMES. + 77 N PIC 9(2) VALUE 2. + 77 I PIC 9(2). + 77 J PIC 9(2). + 77 Q PIC 9(3). + 77 R PIC 9(3). + 77 K PIC 9(5). + 77 B PIC 9(3) VALUE 0. + 77 C PIC 9(3) VALUE 0. + 77 D PIC 9(3) VALUE 0. + 77 P PIC Z(5)9. + 01 num PIC 999 VALUE 0. + 01 num2 PIC 999 VALUE 0. + 01 chickens PIC 999 VALUE 0. + 01 dogs PIC 999 VALUE 0. + 01 total PIC 999 VALUE 0. + 01 result PIC 99 VALUE 0. + 01 result1 PIC 999 VALUE 0. + 01 result2 PIC 999 VALUE 0. + 01 count1 PIC 999 VALUE 0. + + PROCEDURE DIVISION. + + MAIN-PARA. + DISPLAY "ENTER " N " NUMBERS". + PERFORM X-PARA VARYING I FROM 1 BY 1 UNTIL I > N. + PERFORM Y-PARA VARYING I FROM B BY 1 UNTIL C = N. + MOVE K TO P. + DISPLAY "THE LCM IS " P. + + DISPLAY "Enter Number of Head". + ACCEPT num. + DISPLAY "Enter number of legs". + ACCEPT num2. + PERFORM headleg-PARA. + if count1 equals 2 DISPLAY "NONE" + STOP RUN. + + X-PARA. + ACCEPT A(I). + IF (B < A(I)) + MOVE A(I) TO B. + + Y-PARA. + MOVE 0 TO C. + COMPUTE D = D + 1. + PERFORM Z-PARA VARYING J FROM 1 BY 1 UNTIL J > N. + + Z-PARA. + COMPUTE K = B * D. + DIVIDE K BY A(J) GIVING Q REMAINDER R. + IF (R = 0) + COMPUTE C = C + 1. + + headleg-PARA. + PERFORM VARYING chickens FROM 0 BY 1 UNTIL chickens >= num + COMPUTE dogs = num - chickens + COMPUTE result =2 * chickens + COMPUTE result1 =4 * dogs + COMPUTE result2 = result + result1 + IF result2 EQUALS num2 + DISPLAY "[", chickens,",",dogs,"]" + SET count1 to 1 + ELSE IF count1 equals to 1 set count1 to 1 + else set count1 to 2 + END-IF + END-PERFORM. From 4f099f75cc2c2a7d7cce0fe060859af4f43a6a5d Mon Sep 17 00:00:00 2001 From: Samuel Tonini Date: Fri, 4 Oct 2019 07:35:33 -0300 Subject: [PATCH 042/109] Added Dart implementation of Fizz Buzz --- Fizz Buzz/dart_solution.dart | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Fizz Buzz/dart_solution.dart diff --git a/Fizz Buzz/dart_solution.dart b/Fizz Buzz/dart_solution.dart new file mode 100644 index 0000000..371155f --- /dev/null +++ b/Fizz Buzz/dart_solution.dart @@ -0,0 +1,13 @@ +main() { + for (int i = 1; i <= 100; i++) { + if (i % 15 == 0) { + print('fizzbuzz'); + } else if (i % 5 == 0) { + print('buzz'); + } else if (i % 3 == 0) { + print('fizz'); + } else { + print(i); + } + } +} From 60e3472bdfac613e3b61ee806293b86463edceb8 Mon Sep 17 00:00:00 2001 From: Mary Heng Date: Fri, 4 Oct 2019 19:57:03 +0800 Subject: [PATCH 043/109] Added Get Longest Sorted Sequence question. --- Get Longest Sorted Sequence/answer.py | 40 +++++++++++++++++++++++++ Get Longest Sorted Sequence/problem.txt | 3 ++ 2 files changed, 43 insertions(+) create mode 100644 Get Longest Sorted Sequence/answer.py create mode 100644 Get Longest Sorted Sequence/problem.txt diff --git a/Get Longest Sorted Sequence/answer.py b/Get Longest Sorted Sequence/answer.py new file mode 100644 index 0000000..24a404f --- /dev/null +++ b/Get Longest Sorted Sequence/answer.py @@ -0,0 +1,40 @@ +def get_longest_sorted_sequence(words): + count = 1 + total_letters = 0 + current = 0 + increasing_sum = 0 + is_sequence = True + + if len(words) == 0: + return 0 + else: + current = len(words[0]) + + for i in range (1, len(words)): + next = len(words[i]) + if current == next-1: + print(current) + # in sequence + count += 1 + current = len(words[i]) + print(current) + else: + current = len(words[i]) + + return count + + +# test cases +print ('Actual :' + str(get_longest_sorted_sequence(['a', 'is', 'ape', 'in']))) +print () + + +print ('Actual :' + str(get_longest_sorted_sequence(['apple', 'in', 'has', 'wed', 'code', 'rocks', 'bee']))) +print () + + +print ('Actual :' + str(get_longest_sorted_sequence(['apple']))) +print () + +print ('Actual :' + str(get_longest_sorted_sequence([]))) +print () diff --git a/Get Longest Sorted Sequence/problem.txt b/Get Longest Sorted Sequence/problem.txt new file mode 100644 index 0000000..a22267c --- /dev/null +++ b/Get Longest Sorted Sequence/problem.txt @@ -0,0 +1,3 @@ +The function takes in as its parameter a list called words that contains strings. This function first calculates the length of each word, and then returns the count whereby the sequence formed by the length of the words is in increasing order. + +The function calculates the length of every string in the list. It has to then generate a sequence of numbers that are of increasing numberical value and return the length of the longest such sequence generated. \ No newline at end of file From 85bf6d44133fa58f1fa64512d8f729f90aad92ff Mon Sep 17 00:00:00 2001 From: Neeraj Date: Fri, 4 Oct 2019 23:58:54 +0530 Subject: [PATCH 044/109] Added Palindrome program in Python --- Python_Palindrome/PalindromeQues.txt | 9 +++++++++ Python_Palindrome/solution.py | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 Python_Palindrome/PalindromeQues.txt create mode 100644 Python_Palindrome/solution.py diff --git a/Python_Palindrome/PalindromeQues.txt b/Python_Palindrome/PalindromeQues.txt new file mode 100644 index 0000000..bedc45d --- /dev/null +++ b/Python_Palindrome/PalindromeQues.txt @@ -0,0 +1,9 @@ +Given a string, write a python function to check if it is palindrome or not. A string is said to be palindrome if reverse of the string is same as string. For example, “radar” is palindrome, but “radix” is not palindrome. + +Examples: + +Input : malayalam +Output : Yes + +Input : geeks +Output : No \ No newline at end of file diff --git a/Python_Palindrome/solution.py b/Python_Palindrome/solution.py new file mode 100644 index 0000000..aa14a75 --- /dev/null +++ b/Python_Palindrome/solution.py @@ -0,0 +1,22 @@ +# function which return reverse of a string +def reverse(s): + return s[::-1] + +def isPalindrome(s): + # Calling reverse function + rev = reverse(s) + + # Checking if both string are equal or not + if (s == rev): + return True + return False + + +# Driver code +s = "malayalam" +ans = isPalindrome(s) + +if ans == 1: + print("Yes") +else: + print("No") From 03860a208b34aa70103ffdc2e373a10079197ce8 Mon Sep 17 00:00:00 2001 From: tanvibattu Date: Fri, 4 Oct 2019 18:31:49 +0000 Subject: [PATCH 045/109] Added program to find size of tree in C++ --- size-of-tree-C++/problem_statement.txt | 1 + size-of-tree-C++/sizeoftree.cpp | 37 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 size-of-tree-C++/problem_statement.txt create mode 100644 size-of-tree-C++/sizeoftree.cpp diff --git a/size-of-tree-C++/problem_statement.txt b/size-of-tree-C++/problem_statement.txt new file mode 100644 index 0000000..16cfc27 --- /dev/null +++ b/size-of-tree-C++/problem_statement.txt @@ -0,0 +1 @@ +Program to find size of tree in c++ diff --git a/size-of-tree-C++/sizeoftree.cpp b/size-of-tree-C++/sizeoftree.cpp new file mode 100644 index 0000000..89b5c0a --- /dev/null +++ b/size-of-tree-C++/sizeoftree.cpp @@ -0,0 +1,37 @@ +class node +{ + public: + int data; + node* left; + node* right; +}; + +node* newNode(int data) +{ + node* Node = new node(); + Node->data = data; + Node->left = NULL; + Node->right = NULL; + + return(Node); +} + +int size(node* node) +{ + if (node == NULL) + return 0; + else + return(size(node->left) + 1 + size(node->right)); +} + +int main() +{ + node *root = newNode(1); + root->left = newNode(2); + root->right = newNode(3); + root->left->left = newNode(4); + root->left->right = newNode(5); + + cout << "Size of the tree is " << size(root); + return 0; +} From e480cf7199c15b05b6bdd72f74507addac409ce5 Mon Sep 17 00:00:00 2001 From: Antoine He Date: Fri, 4 Oct 2019 22:57:56 +0200 Subject: [PATCH 046/109] Add anagram checking problem --- AnagramChecking/anagram_checking.py | 39 ++++++++++++++++++++++++++++ AnagramChecking/anagram_checking.txt | 3 +++ 2 files changed, 42 insertions(+) create mode 100755 AnagramChecking/anagram_checking.py create mode 100644 AnagramChecking/anagram_checking.txt diff --git a/AnagramChecking/anagram_checking.py b/AnagramChecking/anagram_checking.py new file mode 100755 index 0000000..db37c54 --- /dev/null +++ b/AnagramChecking/anagram_checking.py @@ -0,0 +1,39 @@ +# Python3 program to check if two strings are anagram of each other + +def are_anagram(s1, s2): + """ Check if two strings are anagram of each other. + + Apply XOR to all characters of both strings. If the final value is 0, then + there is an even occurence of all characters, ie the two strings are + anagram. Otherwise, there are not anagram. + + Args: + s1 (str): First string + s2 (str): Second string + + Returns: + bool: True if the two strings are anagram of each other, otherwise False + """ + # Two strings with different sizes can not be anagram of each other + if len(s1) != len(s2): + return False + + # Apply XOR to all characters of both strings + xor_value = 0 + for c1, c2 in zip(s1, s2): + xor_value = xor_value ^ ord(c1) + xor_value = xor_value ^ ord(c2) + + return not bool(xor_value) + +def main(): + """ Driver code """ + s1 = 'listen' + s2 = 'silent' + s3 = 'hacktoberfest' + print('{} / {} -> {}'.format(s1, s2, are_anagram(s1, s2))) + print('{} / {} -> {}'.format(s1, s3, are_anagram(s1, s3))) + print('{} / {} -> {}'.format(s2, s3, are_anagram(s2, s3))) + +if __name__=='__main__': + main() diff --git a/AnagramChecking/anagram_checking.txt b/AnagramChecking/anagram_checking.txt new file mode 100644 index 0000000..43158e6 --- /dev/null +++ b/AnagramChecking/anagram_checking.txt @@ -0,0 +1,3 @@ +Anagram checking + +Write a function that check whether two given strings are anagram of each other. An anagram is a word or phrase formed by rearranging the letters of a different word or phrase using all the original letters exactly once. An optimized solution should have a O(n) time complexity and O(1) space complexity. From 846d3b732c499247fbd21a72299d1e03e2323137 Mon Sep 17 00:00:00 2001 From: jacobstewart20 Date: Fri, 4 Oct 2019 22:08:46 -0500 Subject: [PATCH 047/109] ReverseChars program in java! --- ReverseChars/ReverseChars.java | 26 ++++++++++++++++++++++++++ ReverseChars/problem.txt | 1 + 2 files changed, 27 insertions(+) create mode 100644 ReverseChars/ReverseChars.java create mode 100644 ReverseChars/problem.txt diff --git a/ReverseChars/ReverseChars.java b/ReverseChars/ReverseChars.java new file mode 100644 index 0000000..75aa58d --- /dev/null +++ b/ReverseChars/ReverseChars.java @@ -0,0 +1,26 @@ +class main { + + public static void main(String[] args){ + + System.out.println(reverseChars("These Chars will be in reverse")); + + } + + public static String reverseChars(String reverseIt) { + + int stringLength; + String itReversed; + + reverseIt = reverseIt; + + stringLength = reverseIt.length(); + itReversed = ""; + + for (int i = 1; i <= stringLength; i++){ + char backwardChars = reverseIt.charAt(stringLength - i); + + itReversed += backwardChars; + } + return itReversed; + } + } \ No newline at end of file diff --git a/ReverseChars/problem.txt b/ReverseChars/problem.txt new file mode 100644 index 0000000..bd800af --- /dev/null +++ b/ReverseChars/problem.txt @@ -0,0 +1 @@ +This is a program that takes a given string and loops through the string and places each character in reverse! \ No newline at end of file From 72cd6f1e1834ca66f357a6bc2aced777a88c086c Mon Sep 17 00:00:00 2001 From: JanviMahajan14 Date: Sat, 5 Oct 2019 16:48:00 +0530 Subject: [PATCH 048/109] Added a FANCY cp problem --- FANCY/problem.txt | 32 ++++++++++++++++++++++++++++++++ FANCY/solution.py | 16 ++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 FANCY/problem.txt create mode 100644 FANCY/solution.py diff --git a/FANCY/problem.txt b/FANCY/problem.txt new file mode 100644 index 0000000..50a5747 --- /dev/null +++ b/FANCY/problem.txt @@ -0,0 +1,32 @@ +Chef was reading some quotes by great people. Now, he is interested in classifying all the fancy quotes he knows. He thinks that all fancy quotes which contain the word "not" are Real Fancy; quotes that do not contain it are regularly fancy. + +You are given some quotes. For each quote, you need to tell Chef if it is Real Fancy or just regularly fancy. + +Input +The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. +The first and only line of each test case contains a single string S denoting a quote. + +Output +For each test case, print a single line containing the string "Real Fancy" or "regularly fancy" (without quotes). + +Constraints +1≤T≤50 +1≤|S|≤100 +each character of S is either a lowercase English letter or a space + +Subtasks +Subtask #1 (100 points): original constraints + +Example Input +2 +i do not have any fancy quotes +when nothing goes right go left + +Example Output +Real Fancy +regularly fancy + +Explanation +Example case 1: "i do not have any fancy quotes" + +Example case 2: The word "not" does not appear in the given quote. \ No newline at end of file diff --git a/FANCY/solution.py b/FANCY/solution.py new file mode 100644 index 0000000..056df26 --- /dev/null +++ b/FANCY/solution.py @@ -0,0 +1,16 @@ +# cook your dish here +x=int(input()) +p=0 +flag=0 +while(p Date: Sat, 5 Oct 2019 17:13:55 +0530 Subject: [PATCH 049/109] A phone price problem --- Phone price/solution.cpp | 39 +++++++++++++++++++++++++++++++++++++++ Phone price/statement.txt | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 Phone price/solution.cpp create mode 100644 Phone price/statement.txt diff --git a/Phone price/solution.cpp b/Phone price/solution.cpp new file mode 100644 index 0000000..2c58c78 --- /dev/null +++ b/Phone price/solution.cpp @@ -0,0 +1,39 @@ +#include +using namespace std; + +int main(){ + int t; + cin>>t; + while(t--){ + int n; + cin>>n;int a[n]; + + for(int i=0;i>a[i]; + } + + int j=1;int good =1;int cnt=0;int t=0; + + for(int i=1;i=6)t++; + for(j=i-1;j>=t;j--){ + + if(a[j]>a[i]){ + cnt=1;} + + else { + cnt=0; + break;} + + } + + if(cnt==1) + good++; + + } + + cout< Date: Sat, 5 Oct 2019 21:27:22 +0530 Subject: [PATCH 050/109] Added question-name --- hot_potato/hot_potato.cpp | 193 ++++++++++++++++++++++++++++++++++++++ hot_potato/question.txt | 22 +++++ 2 files changed, 215 insertions(+) create mode 100644 hot_potato/hot_potato.cpp create mode 100644 hot_potato/question.txt diff --git a/hot_potato/hot_potato.cpp b/hot_potato/hot_potato.cpp new file mode 100644 index 0000000..46f73b7 --- /dev/null +++ b/hot_potato/hot_potato.cpp @@ -0,0 +1,193 @@ +#include +using namespace std; + +template +class LinearList{ + private: + int MaxSize; + Item *element; // 1D dynamic array + int len; + public: + /* Default constructor. + * Should create an empty list that not contain any elements*/ + LinearList() + { + element=nullptr; + len=0; + }; + + /* This constructor should create a list containing MaxSize elements. You can intialize the elements with any values.*/ + LinearList(const int& MaxListSize) + { + MaxSize=MaxListSize; + element = new Item[MaxSize]; + len=0; + /*for(int i=0;ik;i--) + { + element[i]=element[i-1]; + } + element[k]=x; + len=len+1; + }; + + +}; + +int main() +{ + LinearList a(250); + int k,n,i,j,temp; + cout << "Enter number of children: "; + cin >> n; + cout << "Enter elimination rule: "; + cin >> i; + for(j=0;j Date: Sat, 5 Oct 2019 19:10:01 -0300 Subject: [PATCH 051/109] Add Generate Parentheses --- Generate Parentheses/Question.txt | 11 ++++++++ Generate Parentheses/Solution | Bin 0 -> 35744 bytes Generate Parentheses/Solution.cpp | 45 ++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 Generate Parentheses/Question.txt create mode 100755 Generate Parentheses/Solution create mode 100644 Generate Parentheses/Solution.cpp diff --git a/Generate Parentheses/Question.txt b/Generate Parentheses/Question.txt new file mode 100644 index 0000000..4b3c0df --- /dev/null +++ b/Generate Parentheses/Question.txt @@ -0,0 +1,11 @@ +Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. + +For example, given n = 3, a solution set is: + +[ + "((()))", + "(()())", + "(())()", + "()(())", + "()()()" +] \ No newline at end of file diff --git a/Generate Parentheses/Solution b/Generate Parentheses/Solution new file mode 100755 index 0000000000000000000000000000000000000000..c1d065fa378a23f8edf45c3e97fdf51b865072e4 GIT binary patch literal 35744 zcmeHwe|%KcweOkyfT$RvVnwt%Qt^UHn#nH`m6`wpXEcG_{IK`~kCVxSj3hJD`2j&i zQ^U24G2T2b*W%Uo<9m8ru21jfS+0+^JR5`(>a%TZsgGJ}qu1Jrs5e#A)T(*kwfEXH zXHI6K#_|5;fyp|1t+m%)d+oK?{xNg*xx-nvGRJ1q)Rn7!O`}v#p~TcM!M>Gm0BW=< z?Iip?Py4bq1L-`0lk^%1K$X`xi&n6J@wtGMuPR3(tnggsQ&4G0FrR7ZKu?*(DyV68 zfuMY(Yy1k41hk7A1xrXFTvZHJK2neJX-nx3uBCPX6f9!>6;$=3y3wbZ=~lQxO3@S~ zUb-6o7-^&Xngt>`2|md36jb^C7WsspGTX=gEn<#FE-#Z^=CVB$RPFH9PG4(f`ByvJ z7I*sm(eB0FRh5e?%ZtN-;!;s>l25#=R=0?fNDQkk=yQ-J9MOO6Y+Lg9j~jpUv#9H% zv9|j>PuO31jq<7wZa?vL7@1B_!+lZ){8lKHj(-)Do1aF`-5KPZlL7yi4EV|n<=%-h z)9Evq0e>0vOvj&-q1<4Gau;Qg;xEk36zt`WE;GTveRlz_|>M_llEO$5?uWl+wLqS;w>>!nG zb+;Mr&dz{`#iq6eGEKj@HL|p6R93pcb^c9VY`lobtuC%y9-mhH?j`HGChqip}+S+9< z!%oEK68A&Q)$Mrk#W&^zLRLi)05!Og+$2@pnYTf+mN28-NXF9{_(~g?(XDKA$hzWnT2_HA%=b7+hCj2=j{J06P=8QxxVm--bUo!D8Wd51J5lvks zCcJDxNvSg7*_47%W5S!~rMd}ko|iS4@KmWJ(nHbi44;CCqa7fHbin z4}WK$UxPbJcMyGaWCGWM_Z>)+%Zv_-^jnlBR~a1?>DMStE;71Xq+g~qP18po66qHx zO|CLJAkx30G`YxVk4Qg5X>yIxph!PWX>y6tn?(9YlqOdgZ4l`vC`~RfS|ierQkt56 zv_z!;2c@aWN9`j0Pn4#n9xW2-?Ube_9@RwpZc0NZ(B9Gbp`Vq+2OXO*ZtM-=Gb@qj#O(7|5M`+wi59&-|5`x3dR&kFF>*GV^khn+Nl#rjG16W< z`~0m!{<;IyipezcUqFog74w9cMIRx*zW<|KJvOHAk6)?V4(ZQ*6qyTw&y`4lvq)ej zc|A*sO^be2?_GKa-L;TDv-G~Dk0KR66&8%^_;V=#Uy!zuIz6P=+Xo;L^&$3kqwV0J zyC%42M{LVuvFNT?%OiTMerH|GInbu}VS3&lA@VVZhN@@K;IS;_cnCPrKb9Ax|w5GKb>dh9r@# z-#N(H%7H?T{%)JzS3jWlw+!}0cl9|RbHxtpvFBp%L-N&7S{FHn;uS)I)a!nc^|9W# zt=hS7cK-ksLZ!(X48<2sF740$K&RBFu z2IIeo9*<%lqOuNC?*5jCq#DBN@BEc2w4?tDR2|I$E4gCBdTjrXU<~ak`V*gJs@1z- zN42H6QIViJ_SKV?vqalRzIJ?xsX_=*nuU&fV5W31o=+}FNwnreMuVoiX8B*f5ttR4n&g4K0V5b?t0_W;h(jiHMz)OUv0spm zG)6IBf!^O>7x%G-g5&e$-B7$om}oydloW-+BHxq1qHY7!5y(oSY(Ykk!#I|S)&rUz zds-H$v;js4{RRq0ZC@WJ=^z~$%9~W^xj)p_y!8v3PyH}bKg6hYU zks&|+B~(wkV{J28u>s=t!iu}~Sj#T6SUG&`g=1fYA^s_HThg(a~f-myCoXd1zR8bK5He>BS4QJ*I_`!kD>Tc3K57S)E@gs@};3i^!`~nLO|>- zc8;frZ^(IAba2+7RKx*_Zm7dh+@K=*N<=>NlfD)d^jo31Ec>wD>pX0iVu#}IpkA)n zLCL+A3@C)m6GABW;kwvMdhA6KaE21V1^-ZV3UXsqQMfT6j3M0kQ6kF91KU`Hp%Bt= zd%C{pIX(7_zW;qx^LdFoSx?k(p(t4x4T=}Bh{HO%BktjHN$c2T(Xoc20gx#E%Ta3f z)_&M$w3k~f@(yg)yXCMJ{R-Gp?5iY*CfkOV6+K?G>oJiVCDcpED2hHRQAiHOSBMyKKr{l96(T9zlU5G0n4$Px zH0ppS=@gi{oO6O4;h@grT5XGr01HtQv{n@QwNP8b*M{P&Fs8X;KdtNY4%fwA{fQmz z9a@}|*F z4rXYgB8+q*x=}nLyF!ELAhg*#$+l9tVX_D2GpuV1jn|6~=&=`o8N@&*XAGEG%MkVO zTc9)VBH~SEohOp$6f%0j48q`B#TcOJHXz{poc9f?f31jUV^cozp~R_;bQZ-aE=04KsBdhd(zej<>=@R+G)6k>Li(ii^`oT?97 z$5NsHS*(8?t$;d+*mZ}@lv-mEBZlJJsc5<%f}PZD4K1Y^T~kE&$ugzAI5&M$VkJ#h z+GFBMOlDHGnVjhXso0np-Kn_V!2(m8KxZNq3Eg`Kp_TAouc@dME7J5}D87$`!sbGK zkpbI&qN38L;8L=FLZ1{z`1=&ecI9}Jy;%Ap=3IZvI^9Y|V9rHhiDo2;71h@NRKA=j zm+d-7=!qd6Fr8*{nj{uV+{O)NPNCgo&CLC)l}bp{zsBA)=|pm5-=Mi#45MBj&Dl~W zX=S3|G_5HuUITea4@ng`S=d|%19z%4wu#+LgI?xU0$9>@9W>zO&aucjvb~4m&x$c) zC_X|{lwRk!{rK-Dl{VQEe-3U{g@pU^%s;aq$apkFCDPOg*5IJ9N1(`YVbUTQ@`mEy zO<+f8Tp*3ju5#@g)GX32Rvj{V>;jYCseUc`LKjxOs#=Q7rmjFvRhl)*Fw5y=!fNN( z>~GT=H9tOnoa42arVYh+zMk+SOt#NnG$&m%lcPixs*0Fz zo^8MbX!_GnV}Xc9TToS)vs$8t;!h$i2W|MuP<)oyun}_}GK%5~(tWQpZa==8%yztt zcsIR94I-9UhgmvJ7vgKEp)gt9Bp?bNir+@Jy$7p4e)zc;CH0QkRBNy&l7lA}&*a#u zGbZWW;EYHbWp1MVxp({qMoZNAkeq(~0&$XdEl=U)$gxp0BM;+hR%#X`Z1v@Y>CmBu z;$TUoV*ih(iFN%8UY#qpQWw7o*i;+)&=q^P zZV|2e3-tXT=Ei>+C*|IV*d4!9`Riiu*Tvpl5&O^Di8;sg-UBwh`uEY-P;SBX>u5?? zdt43D_dIIoSz@vb#1C9gE z!pd{T*u=!8fHi=1fcF4)5+3vX9f0!z_W*tk@Ce|&fa8D<0?vhz4gppH-h;{iO=L8z z{q6xg5AZR-ld&Ki25bZz1H2Eg2!?$IumtcZU<2T#?@dfZ02={!0B!@^19%AV2;fVA zCje(+qCN+WLc1E}fFZzU!0!P@0G|ci0eBv!?t1`h0FMCP40r zngL4zBY>*`cK}`sxCd}O;1R%w08aoO0-OV9I09G>comjS&46nGBY?L9?g0D_;2yxe zfJXq|2Rs2d2cyp%IMPbMa=@Dbn*pPM5x@b!9e@u3?g4xa@Ce{XfF}U|Cqm)5@QWjW zR{)*>ya6yD>xSC^&j5T7@CLwrfcF6&1ElX;YT!roJB@A8YwE}Tyy zDE|t4=0Yx-B5_gP8}NA;E8@4K1V>u&J+R_)2~X>32nQj zp-$9f<^wHf*|l?IeWZS*apsc+}^z0t{iYuIfp^N8F7_tn&4r35}o37dj`54bXxtjg5H4p zyh}{wt;HY_p;<6 z8F_h#l^8p8Gf&QP!9es2LB9_4SAc#y=w)WQKPjKauI-?wvzr}xwu0UR zdb2q{>1c`tG~Vq7PbNP-4EmFxSD0l4lRCsfe-`wwndwvkq^S-C82?@aJ(K^?j_x0) zC|?KtIOyr>Nb);Ce*yFx%;o2NT_`~GZJ>V%<8-;19!To93-pUY&scxZOF*Z2Nx~0u zWUwXqanM^qpKqqGOUf^pp=oWPr}JIPzYugk=$U*(2mL=uvb29Oie z;@FTynH3D7f@Ujq8>5sQ4bqaFDhK>sc1_%%<`Mh#Mb zLao3j0-g?(;U&bf!lJ*=Synjr-dty)y+3bR;lg|J^}>?7X6S`gy))|zYeI!pwS^_M zg$tJz+QA3@WrYP|&A1P8$d+i0#5FNtn|I9>(9xEUrC8jC--6wrlmDw6?dLh@8lcX0 z=09#jIDXKk{lbQz2-L|-w!CQ5-sTixfPP?s?VM_ic>mjWr!AgqdnsqBru{>n^Jt#- zY96wIMO?(ppMq8StF=}V`M}w>*_Y&pZ86))|6tSpI|)|&2}QrS`N9HUSl|l_d|`nv zEbxT|zOcX-7Ragv)N?NCxfb;ti<*a7Aw9E0m%`ICI&{sFKpW#5-e%R>Xi<)OILvpVBkkiyftfi9(Y0UL_ZiSo~r zYzaPWk&F6)U1Y_UwMgH@8L@RO(n?P((L{Pa)3K#5(%8QFe6FSTv~n-vhOT6|lHoNB z+Zk?Tco)O_7=Dl8lMD|re4gQ}4BurqLoDd92gL9qhLsFgGQ5UiJHxcfe*&a>eoL|9 z$+^qy3tL*F{z%lm1P{oSEOtai%5l4+s<@=Q*s)0BRgTP%o>;3=j%H$`r{>gi@g_8U zG*^qH<i&Xx6P4$OV{0vR?n^gQvP5DzQzCcrcn2JA1tdq?+y3a-LQ~knB%f+{d zDn6v*XK6*;zNz?AwP2d|%hd`K=P;!5&rZafRD6*ZNKq~%pZRBsv7JvW8NbH|E2}Ml<{|3@M{>qmGOBj-_Q7M7W}=8zsG{#&G-Qe z{yE0)u;AZi{7wu0OvD$e*Mk=P62?Dd!BdN(jHtf?vz{K?}Zz@dqvVhZ%p^f`69r&sy;BF@D&BpPwi7Iby+I z&G@4he30?SEcp8wKVrfEl<}`v@NY0aZo$*f`pG`8Tkw}Le$0ZWeLCVlVZqb)FoYks z;Qy8JA6W48`w8OL7DxxrV?Y0p@p%^fS1_R?{sIf$#rRnke3ZD;&8wzH4R{SV;N$ytp0r;~FB@E4%I z>O2P(#~xt*Id&;H%JMg$ymaz^2t3JeVgsoDI~#$H@Rh9R3YPQCLXtCizP*n5Z{&); z&ip@SytTjomGRG>Eg8eiA3(^Xa&P2?vhuy3GX8$j{v46}S|eAv(Uc^o&m8MN8x$fVCO=ydTgrrivD zI{90f-^uk-_B;+e>1p+o_n6;0Pgo-SP?l-_dqW1iU*IuLak*a3bUV_de3kRC z=W_ctGe7;1gZMA7`1w_sAE>-$ecChNzXd$WvG$kWGX5$yu=2x8Fs~*4yX{iCvfB>E z_ppD~apA8p{&}vi@}DYnD3bGgmVH4ZOWB;{PldNR=N zX8eO}9~GbfgYnk*c^Nt^>GKvVuHw=?jPGPWQTP*#pUdrHXFZpp!>02SH}HywSp^6J zPvtgq|5D@NON?)0zg7M2HO9~4IM&F*YA;PM|9ap_KJ`DkU`BE6Vf-&RUMYV&cd_KR zwtE=(boJ6ap-4CqZEr93Xvy>bj7XQ^p%ee;{Ij-zvA#3V>h3h!@ccp8a7Vi}PoOK< z>5X{XikDPYFGl&656b_humFWqb=IiwHaAVDLlyFi=?nN1v;Y< zU%+4N2?oU>cXf{HpwH{^Zt{h_h9}_1L4i>Z4q(IicXf_3@i>GV>OshQiLCUk_Xk2a zu8=sY48s?oLXcctjq?coQ95_9uGE40dE4F5&WM3y^EMd4K&Q{M*~xNCK=XzKg)t7) z!-xdTs1kQuASknwbezXmfzuJa-BL@pKN7C1@Of|`B1uh4uJi}O(bjNAdKKjRy6E7; zOcIuO0-c>WlP)8Jqr|zqzP8B|@&zLqnJUB?j2X#Q-tGtvKJ>O_+{-I-B}qpXY0a8zyjv3&kO#ApqCygcIbenP(1z@|@Bu6GK) zYFQ1pU$|mgr*V`^9#YL8?VO?xm68#iCW13^1JTTm=3v%f$h*;SZ^UtjnQKzs9tc73 z$D6u@8N*XJjzdZF2heSTQ`CA1OKbOq!Vx3j@0^0SOq|*YfgjU19LyKl9Gs#Dl}auz z4tbo4jSHnyMnm5A%=Y6#TSIglX{LVdV6LD$Zc zbye%Ves2ikd_LbajzM)cHbpAsGkh+brHbQh@z)9Mjg^hH^-jaNdIcT4Yv3em!>Kb; zU(u);E3RE#Tkl#9TFNllmWmKZ_a?MnvvOsVv)O2_T~_C$Q(`HER3=ABK2;Y=Os6JJ zrvoD+OY@>)l}1BTg@N;3MLDI$HR4f4aSHIX3LxWDz&OiG>6qI}Re@4t1vOG&GtEI< zb*&{%C&qHoaDmOPhUryhW3$mzoh%_+s$;-nQ9ewS2W>MGwGJ}_s zC8_q-1IcS@OeaE1^MBfd&()dPDb=I1rfG3h-WAyBb(uz|>BLcr*urnth><4bC82mu z9m^-L-{W;P8_seuy;{?>3_d05sE*BMt#B?jorW#OkWX7d>8<6)logz2|8{>CAi;<)%0uKgIrN=C*La=)mlXUK;>ct5O5_^upoBhUU*B%BDhD?cVJMiG>Se=o-A&FlP1CI}jS`=0WgVij zE52Tg7+IX*1sRCV;Z5$~G-tMGm};+|UfE&z+FfhIAp`_NEOlI0iCfw^aG~`ou&@Xl zktlZb@aBRIB3L`o$sNFo;FQ>I^Ff#k;RRGjm7==CVQjTgIfCSLR$%EB#Zbl(zY!Ul z>V)4-<8=@G!jCj<0Ub(=dM=Rl^N(5y^Xs}qhwlYy(m(hXC|RQqPhB2``PZX@wB82ADf z_wKf~kT)C-v`@n2XOY#m!?62+Rvg=ciMW!i6eSj)pMMczsGwvO6cW>aZiCw$T+($7W)vIj{ualP)*|0NS_hmf+ z&P8Lb?5yT7J>3ow*f8`soiyR$`Oc?Z3z*(smeS{w>wzpyqMDgih-BDf7;{@wYeIvo=yo)SiMn1 z#z|Ww=%_qn&iYu3Z3lXtUt%{=?$(R9l_f)g+UK_e)pecPZM2Lb*pK4#T1C!l#5ojou$<>0a{9fSzzve3b{M!n}!ILP`EtZe4N6jX_gvb5Cz40MjMfo~7|Y zZV}=O(ki17YYkCwa#L=r}v5Vyx2CNc$=KwcloC2 z`H7Vv_W|)0g>!Y2LGMhpetU+m%Q0FxD%yPQ{I!K4zOsNqPNPYu-eS@zD?29UP1$61 zvm#oK4pY6y7vJP%xy+PJnUvS6A`bF9P{lx+4eyrAwPZx4pBqvWVP=rMKB~spEE{Tx z`q2XXQf`omQ0)E2^!(h}3Ll*`A;NcV{8dnvwO2!6mbUUz-szmpErX<$Y3x(`7}7_w z;eozxTGv_M_G=yTQ(vqt_U`-^KMH>og#rXclTZ~sl zFOIm^a|*v}E^dwbI@=ce+O%Ryb-2SFT5;QEKjcXm2}#OEypJ6}c1uYZpoP4hZpy%S z!OnevQ8(;1-7h;x{_Q-VXjncSjq9s1&5*P20RSM?LUGun;DH z>@8)edz9(!@_C>o{phC{vvsW)KQ!;c1~~ufefoeNo3P=do<~sUfGEh12P6t0Uh_qd zAU+V4hS=}a9}zB>0r!OJ+G z(qHi@xB+xJqerFH`6vnwaDLLC^i=vYTDt`|WK)%2og1W}IyXp_ukx$}m@lpl{eCdya&?*)!nNI$yNxhx7&9`j{w{}_no{ObG`1#hw#9FN(GOTitM{OX(+ z1yy}HTS9+@|BfYp4?l3C;LH3RjmodeRq2N<`P(j(6a`OGj0~;y{};}$+D|?2t>Dis z`IX)Z{l6^vYZgd~g7oeT^JOjnCm@oE6`MM*MnTcJOaiRs|IC`dR5GjcZ5}e^rCV$H zzXOg;PQFc-I&UC;g-l!Rt;$#MPhg{GkW_wkPR=;zSA0@h(tj2HZ4gx75;sQC1xb4W~h9}%&6DMR0;Q=bCJ9OAEl3~7xfRN jyUZc~cDG2l6VG>(es7r@)z|=jv`A2OH%v)WQ&kH literal 0 HcmV?d00001 diff --git a/Generate Parentheses/Solution.cpp b/Generate Parentheses/Solution.cpp new file mode 100644 index 0000000..3153f05 --- /dev/null +++ b/Generate Parentheses/Solution.cpp @@ -0,0 +1,45 @@ +#include +using namespace std; + +void generate(int n, int opening, int closing, string combination, vector& result) { + int size = combination.size(); + if(size == n && closing == opening) { + result.push_back(combination); + return; + } + + if((closing < opening) && (size > 0)) { + combination.push_back(')'); + generate(n, opening, closing+1, combination, result); + combination.pop_back(); + } + + if(size < n-1) { + combination.push_back('('); + generate(n, opening+1, closing, combination, result); + combination.pop_back(); + } +} + +vector generateParenthesis(int n) { + vector result; + string combination; + generate(2*n, 0, 0, combination, result); + return result; +} + +int main() { + + int n; + vector result; + + scanf("%d", &n); + + result = generateParenthesis(n); + + for(int i=0; i Date: Sat, 5 Oct 2019 22:06:19 -0500 Subject: [PATCH 052/109] Create sleep_in.py --- Sleep_In/sleep_in.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Sleep_In/sleep_in.py diff --git a/Sleep_In/sleep_in.py b/Sleep_In/sleep_in.py new file mode 100644 index 0000000..efa6144 --- /dev/null +++ b/Sleep_In/sleep_in.py @@ -0,0 +1,7 @@ +"""The parameter weekday is True if it is a weekday, and the parameter vacation is True if we are on vacation. We sleep in if it is not a weekday or we're on vacation. +Return True if we sleep in.""" + +def sleep_in(weekday, vacation): + if not weekday or vacation: + return True + return False From ea2723309beb8f63e7183bd99974085776cb7270 Mon Sep 17 00:00:00 2001 From: martinezhenry <7996045+martinezhenry@users.noreply.github.com> Date: Sat, 5 Oct 2019 23:42:06 -0500 Subject: [PATCH 053/109] Added Octal Decimal Calculator --- .../Octal Decimal Calculator.txt | 9 ++++ .../OctalDecimalCalculator.java | 43 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 Octal Decimal Calculator/Octal Decimal Calculator.txt create mode 100644 Octal Decimal Calculator/OctalDecimalCalculator.java diff --git a/Octal Decimal Calculator/Octal Decimal Calculator.txt b/Octal Decimal Calculator/Octal Decimal Calculator.txt new file mode 100644 index 0000000..41b563a --- /dev/null +++ b/Octal Decimal Calculator/Octal Decimal Calculator.txt @@ -0,0 +1,9 @@ +Given an octal number it is required to convert to decimal and print it on the console + +Example: + +The octal number 567 is entered. + +The system calculates the equivalent number in decimal that is 375 and prints it on the console + +The decimal number for octal 567 is: 357 \ No newline at end of file diff --git a/Octal Decimal Calculator/OctalDecimalCalculator.java b/Octal Decimal Calculator/OctalDecimalCalculator.java new file mode 100644 index 0000000..596c7d5 --- /dev/null +++ b/Octal Decimal Calculator/OctalDecimalCalculator.java @@ -0,0 +1,43 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class OctalDecimalCalculator { + + private static int BASE_8 = 8; + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final String RESULT_TEMPLATE = "The decimal number for octal %s is: %s"; + + public static void main(String[] args){ + + System.out.println("Please input octal number to convert"); + try { + String octal = br.readLine(); + String decimal = convertOctalToDecimal(Integer.parseInt(octal)); + + System.out.println(String.format(RESULT_TEMPLATE, octal, decimal)); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + public static String convertOctalToDecimal(int octal){ + int result = 0; + String tmp = String.valueOf(octal); + int count = 0; + int multiple; + String caracter; + for (int i = tmp.length(); i > 0; i--) { + caracter = tmp.substring(i-1, i); + multiple = (int) Math.pow(BASE_8, count); + int value = (Integer.parseInt(caracter) * multiple); + count = count + 1; + result += value; + + } + + return String.valueOf(result); + } + +} From 27c0bcd7af857ed49b61632c92741a85fccc3a46 Mon Sep 17 00:00:00 2001 From: Udit Rai Date: Sun, 6 Oct 2019 12:13:35 +0530 Subject: [PATCH 054/109] Added question alphacode --- alphacode/problem_statement.txt | 34 +++++++++++++++++++++++++++++++++ alphacode/solution.txt | 32 +++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 alphacode/problem_statement.txt create mode 100644 alphacode/solution.txt diff --git a/alphacode/problem_statement.txt b/alphacode/problem_statement.txt new file mode 100644 index 0000000..9902844 --- /dev/null +++ b/alphacode/problem_statement.txt @@ -0,0 +1,34 @@ +Alice and Bob need to send secret messages to each other and are discussing ways to encode their messages: + +Alice: “Let’s just use a very simple code: We’ll assign â€A’ the code word 1, â€B’ will be 2, and so on down to â€Z’ being assigned 26.” + +Bob: “That’s a stupid code, Alice. Suppose I send you the word â€BEAN’ encoded as 25114. You could decode that in many different ways!” +Alice: “Sure you could, but what words would you get? Other than â€BEAN’, you’d get â€BEAAD’, â€YAAD’, â€YAN’, â€YKD’ and â€BEKD’. I think you would be able to figure out the correct decoding. And why would you send me the word â€BEAN’ anyway?” +Bob: “OK, maybe that’s a bad example, but I bet you that if you got a string of length 5000 there would be tons of different decodings and with that many you would find at least two different ones that would make sense.” +Alice: “How many different decodings?” +Bob: “Jillions!” + +For some reason, Alice is still unconvinced by Bob’s argument, so she requires a program that will determine how many decodings there can be for a given string using her code. + +INPUT + +Input will consist of multiple input sets. Each set will consist of a single line of at most 5000 digits representing a valid encryption (for example, no line will begin with a 0). There will be no spaces between the digits. An input line of â€0’ will terminate the input and should not be processed. + +OUTPUT + +For each input set, output the number of possible decodings for the input string. All answers will be within the range of a 64 bit signed integer. + +Example + +Input: + +25114 +1111111111 +3333333333 +0 + +Output: + +6 +89 +1 diff --git a/alphacode/solution.txt b/alphacode/solution.txt new file mode 100644 index 0000000..7d8b958 --- /dev/null +++ b/alphacode/solution.txt @@ -0,0 +1,32 @@ +#include +#include + +using namespace std; + +int main(){ + int L; + char d[5001]; + long long dp[5001]; + + while(true){ + scanf("%s",d); + if(d[0]=='0') break; + + L = strlen(d); + + dp[0] = dp[1] = 1; + + for(int i = 2;i<=L;++i){ + dp[i] = 0; + + char c1 = d[i-2]-'0', c2 = d[i-1]-'0'; + + if(c1==1 || (c1==2 && c2<=6)) dp[i] += dp[i-2]; + if(c2!=0) dp[i] += dp[i-1]; + } + + printf("%lld\n",dp[L]); + } + + return 0; +} From fb8b3a3f124a1c8dcae4138d3b6283a66dafac27 Mon Sep 17 00:00:00 2001 From: rishabhsingh20 Date: Sun, 6 Oct 2019 16:40:04 +0530 Subject: [PATCH 055/109] A programming question with solution in c++ code --- Save the Prisoner!/question.txt | 60 +++++++++++++++++++++++++++++++++ Save the Prisoner!/solution.cpp | 20 +++++++++++ 2 files changed, 80 insertions(+) create mode 100644 Save the Prisoner!/question.txt create mode 100644 Save the Prisoner!/solution.cpp diff --git a/Save the Prisoner!/question.txt b/Save the Prisoner!/question.txt new file mode 100644 index 0000000..0d33d53 --- /dev/null +++ b/Save the Prisoner!/question.txt @@ -0,0 +1,60 @@ +A jail has a number of prisoners and a number of treats to pass out to them. Their jailer decides the fairest way to divide the treats is to seat the prisoners around a circular table in sequentially numbered chairs. A chair number will be drawn from a hat. Beginning with the prisoner in that chair, one candy will be handed to each prisoner sequentially around the table until all have been distributed. + +The jailer is playing a little joke, though. The last piece of candy looks like all the others, but it tastes awful. Determine the chair number occupied by the prisoner who will receive that candy. + +For example, there are 4 prisoners and 6 pieces of candy. The prisoners arrange themselves in seats numbered 1 to 4. Let's suppose two is drawn from the hat. Prisoners receive candy at positions 2,3,4,1,2,3. The prisoner to be warned sits in chair number 3. + +Function Description + +Complete the saveThePrisoner function in the editor below. It should return an integer representing the chair number of the prisoner to warn. + +saveThePrisoner has the following parameter(s): + +n: an integer, the number of prisoners +m: an integer, the number of sweets +s: an integer, the chair number to begin passing out sweets from +Input Format + +The first line contains an integer, t, denoting the number of test cases. +The next t lines each contain 3 space-separated integers: +-n : the number of prisoners +-m : the number of sweets +-s : the chair number to start passing out treats at + +Constraints +- 1<=t<=100 +- 1<=n<=1000000000 +- 1<=m<=1000000000 +- 1<=s<=n +Output Format + +For each test case, print the chair number of the prisoner who receives the awful treat on a new line. + +Sample Input 0 + +2 +5 2 1 +5 2 2 +Sample Output 0 + +2 +3 +Explanation 0 + +In first query, there are n=5 prisoners and m=2 sweets. Distribution starts at seat number s=1. Prisoners in seats numbered 1 and 2 get sweets. Warn prisoner 2. +In the second query, distribution starts at seat 2 so prisoners in seats 2 and 3 get sweets. Warn prisoner 3. + +Sample Input 1 + +2 +7 19 2 +3 7 3 +Sample Output 1 + +6 +3 +Explanation 1 + +In the first test case, there are n=7 prisoners, m=19 sweets and they are passed out starting at chair s=2. The candies go all around twice and there are 5 more candies passed to each prisoner from seat 2 to seat 6. + +In the second test case, there are n=3 prisoners, m=7 candies and they are passed out starting at seat s=3. They go around twice, and there is one more to pass out to the prisoner at seat 3. diff --git a/Save the Prisoner!/solution.cpp b/Save the Prisoner!/solution.cpp new file mode 100644 index 0000000..42768a6 --- /dev/null +++ b/Save the Prisoner!/solution.cpp @@ -0,0 +1,20 @@ +#include +using namespace std; +int main() +{ + int t,n,m,s; + cin>>t; + while(t>0) + { + cin>>n>>m>>s; + s=s+m%n -1; + if(m%n==0) + s=s+n; + if(s>n) + s=s%n; + cout< Date: Sun, 6 Oct 2019 09:58:15 -0300 Subject: [PATCH 056/109] Add solution in C and C++ --- Fizz Buzz/fizzbuzz.c | 12 ++++++++++++ Fizz Buzz/fizzbuzz.cpp | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 Fizz Buzz/fizzbuzz.c create mode 100644 Fizz Buzz/fizzbuzz.cpp diff --git a/Fizz Buzz/fizzbuzz.c b/Fizz Buzz/fizzbuzz.c new file mode 100644 index 0000000..11830ea --- /dev/null +++ b/Fizz Buzz/fizzbuzz.c @@ -0,0 +1,12 @@ +#include +void main() +{ + int i; + for(i=1;i<=100;i++) + { + if(i%3!=0 && i%5!=0) printf("%d\n", i); + if(i%3 == 0 && i%5!=0)printf("Fizz\n"); + if(i%5 == 0 && i%3!=0)printf("Buzz\n"); + if(i%5 == 0 && i%3==0)printf("FizzBuzz\n"); + } +} \ No newline at end of file diff --git a/Fizz Buzz/fizzbuzz.cpp b/Fizz Buzz/fizzbuzz.cpp new file mode 100644 index 0000000..22eea15 --- /dev/null +++ b/Fizz Buzz/fizzbuzz.cpp @@ -0,0 +1,16 @@ +#include +using namespace std; +int main() +{ + for(int i=1;i<=100;i++){ + if((i%3 == 0) && (i%5==0)) + cout<<"FizzBuzz\n"; + else if(i%3 == 0) + cout<<"Fizz\n"; + else if(i%5 == 0) + cout<<"Buzz\n"; + else + cout< Date: Sun, 6 Oct 2019 10:00:37 -0300 Subject: [PATCH 057/109] Add a blank line in file --- Fizz Buzz/fizzbuzz.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Fizz Buzz/fizzbuzz.c b/Fizz Buzz/fizzbuzz.c index 11830ea..4640b18 100644 --- a/Fizz Buzz/fizzbuzz.c +++ b/Fizz Buzz/fizzbuzz.c @@ -9,4 +9,4 @@ void main() if(i%5 == 0 && i%3!=0)printf("Buzz\n"); if(i%5 == 0 && i%3==0)printf("FizzBuzz\n"); } -} \ No newline at end of file +} From d36253be9b4b119da52658128fb389ff1008c828 Mon Sep 17 00:00:00 2001 From: Rodolphe Date: Sun, 6 Oct 2019 20:29:44 +0200 Subject: [PATCH 058/109] add a new js problem + --- Counting-Change-Combinations/counting.txt | 13 ++++++++++++ Counting-Change-Combinations/solution.js | 24 +++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 Counting-Change-Combinations/counting.txt create mode 100644 Counting-Change-Combinations/solution.js diff --git a/Counting-Change-Combinations/counting.txt b/Counting-Change-Combinations/counting.txt new file mode 100644 index 0000000..e7aba7c --- /dev/null +++ b/Counting-Change-Combinations/counting.txt @@ -0,0 +1,13 @@ +Write a function that counts how many different ways you can make change for an amount of money, given an array of coin denominations. For example, there are 3 ways to give change for 4 if you have coins with denomination 1 and 2: + +1+1+1+1, 1+1+2, 2+2. +The order of coins does not matter: + +1+1+2 == 2+1+1 +Also, assume that you have an infinite amount of coins. + +Your function should take an amount to change and an array of unique denominations for the coins: + + countChange(4, [1,2]) // => 3 + countChange(10, [5,2,3]) // => 4 + countChange(11, [5,7]) // => 0 \ No newline at end of file diff --git a/Counting-Change-Combinations/solution.js b/Counting-Change-Combinations/solution.js new file mode 100644 index 0000000..fcb7e85 --- /dev/null +++ b/Counting-Change-Combinations/solution.js @@ -0,0 +1,24 @@ +let countChange = function(money, coins) { + if (coins.length === 0) { + return 0; + } + + coins = coins.slice(0).sort(); + let result = 0, + largestCoin = coins.pop(), + maxCount = 0; + let maxRemain = money % largestCoin; + + if (maxRemain === 0) { + result++; + maxCount = money / largestCoin - 1; + } else { + maxCount = (money - maxRemain) / largestCoin; + } + + for (let i = maxCount; i >= 0; i--) { + result += countChange(money - largestCoin * i, coins); + } + + return result; +} \ No newline at end of file From 3ac3ee03e6079c22fae2115d6957a154517e534d Mon Sep 17 00:00:00 2001 From: AmarGwari Date: Mon, 7 Oct 2019 02:20:40 +0530 Subject: [PATCH 059/109] I am submitting my problem, please merge it after reviewing --- ToyObsession/problem.c | 7 +++++++ ToyObsession/solution.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 ToyObsession/problem.c create mode 100644 ToyObsession/solution.c diff --git a/ToyObsession/problem.c b/ToyObsession/problem.c new file mode 100644 index 0000000..d59efa2 --- /dev/null +++ b/ToyObsession/problem.c @@ -0,0 +1,7 @@ +We are to input a string of characters(say, s1= XxxyXxxXXxY) and a character(say, X) that belongs to that string +( The string represents the collection of toys and the character represents the most beautiful toy) + we are to input a number that denotes the no. of beautiful toys needed ( smaller than equal to the maximum beautiful toys, say 2 ) + now we are to print the smallet length (as in no. of characters) of the substring +eg here 2 X containing substrigs are... XxxyX XxxX XX + 5 4 2 + max min therefor 2 printed. \(>o<)/ diff --git a/ToyObsession/solution.c b/ToyObsession/solution.c new file mode 100644 index 0000000..0855193 --- /dev/null +++ b/ToyObsession/solution.c @@ -0,0 +1,40 @@ +#include +#include +int main() +{ + long long int T,m; + scanf("%lld",&T); + for(m=0;m=0) + { + brr[i] = arr[j]-arr[j-(N-1)]+1; + i++; + j--; + } + + for(l=0;l Date: Mon, 7 Oct 2019 04:32:44 +0530 Subject: [PATCH 060/109] added omar loves candies from a2oj --- Omar and Candies/Problem Statement.txt | 24 ++++++++++++++++++++++ Omar and Candies/Solution.c | 28 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 Omar and Candies/Problem Statement.txt create mode 100644 Omar and Candies/Solution.c diff --git a/Omar and Candies/Problem Statement.txt b/Omar and Candies/Problem Statement.txt new file mode 100644 index 0000000..4e3391e --- /dev/null +++ b/Omar and Candies/Problem Statement.txt @@ -0,0 +1,24 @@ +Omar can get as many candies as he wants but all of them must be of the same type. Find the candy having the biggest quantity in the store so that Omar can have maximum number of candies. + + +Input Format: + +The first line of the input will be a single integer T, the number of test cases (1 <= T <= 100). Followed by the test cases, each test case is described in one line which contains a non-empty string which consists of up to 100 letters, each letter is a lower case English letter (from 'a' to 'z'). This string represents all candies in the store, each candy is described using 1 character, so if the string is "abac" this means the store contains 2 candies of type 'a', 1 candy of type 'b' and 1 candy of type 'c'. + + +Output Format: + +For each test case, print a single line which contains a single integer representing the maximum number of candies that Omar can get followed by a space then a letter which represents the kind of that candy. If there are multiple candies with the same number, print the one which occurs relatively first in the English alphabet. + + +Sample Input: +3 +abac +abc +zzz + + +Sample Output: +2 a +1 a +3 z diff --git a/Omar and Candies/Solution.c b/Omar and Candies/Solution.c new file mode 100644 index 0000000..ac37faf --- /dev/null +++ b/Omar and Candies/Solution.c @@ -0,0 +1,28 @@ +#include +#include +#include + +int main() +{ + int t; + scanf("%d",&t); + while(t--){ + char str[100]; + scanf("%s",str); + int i; + int *arr = (int*)calloc(26,sizeof(int)); + for(i=0;imax){ + max = arr[i]; + c=i; + } + } + printf("%d %c\n",max,c+97); +} + return 0; +} From 0baf458a93e1805abb33c032905fc462915a765c Mon Sep 17 00:00:00 2001 From: Ankit Mehta <54588691+IamAnkit55@users.noreply.github.com> Date: Mon, 7 Oct 2019 13:58:33 +0530 Subject: [PATCH 061/109] Create question.txt Explained what is Palindrome. --- Palindrome/question.txt | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Palindrome/question.txt diff --git a/Palindrome/question.txt b/Palindrome/question.txt new file mode 100644 index 0000000..6e1fc41 --- /dev/null +++ b/Palindrome/question.txt @@ -0,0 +1,6 @@ + +A palindromic number (or a numeric palindrome) is a number that remains the same when its digits are reversed. +Like 16461, for example, it is "symmetrical". + +This program reverses an integer (entered by the user) using while loop. +Then, if statement is used to check whether the reversed number is equal to the original number or not. From bdebdbc47ff29c71af8edbe476d9b58f33070ed7 Mon Sep 17 00:00:00 2001 From: Ankit Mehta <54588691+IamAnkit55@users.noreply.github.com> Date: Mon, 7 Oct 2019 14:00:13 +0530 Subject: [PATCH 062/109] Create Palindrome.c Used while loop to identify whether the given number is palindrome or not. --- Palindrome/palindrome.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Palindrome/palindrome.c diff --git a/Palindrome/palindrome.c b/Palindrome/palindrome.c new file mode 100644 index 0000000..3eed551 --- /dev/null +++ b/Palindrome/palindrome.c @@ -0,0 +1,22 @@ +#include +int main() +{ + int n, reversedInteger = 0, remainder, originalInteger; + printf("Enter an integer: "); + scanf("%d", &n); + originalInteger = n; + // reversed integer is stored in variable + while( n!=0 ) + { + remainder = n%10; + reversedInteger = reversedInteger*10 + remainder; + n /= 10; + } + // palindrome if orignalInteger and reversedInteger are equal + if (originalInteger == reversedInteger) + printf("%d is a palindrome.", originalInteger); + else + printf("%d is not a palindrome.", originalInteger); + + return 0; +} From a3ffe60fe1b1c1cf0bfbcc14bc24e380e8358c03 Mon Sep 17 00:00:00 2001 From: Rodolfo Quispe Date: Mon, 7 Oct 2019 17:49:14 -0500 Subject: [PATCH 063/109] Added chusky and hunger problem --- chusky_hunger/problem_statement.txt | 41 ++++++++++++++++ chusky_hunger/solution.cpp | 75 +++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 chusky_hunger/problem_statement.txt create mode 100644 chusky_hunger/solution.cpp diff --git a/chusky_hunger/problem_statement.txt b/chusky_hunger/problem_statement.txt new file mode 100644 index 0000000..5625b7b --- /dev/null +++ b/chusky_hunger/problem_statement.txt @@ -0,0 +1,41 @@ +Chusky and Hunger +========================= + +Chusky lives in Dogland and as everyone in this city, he loves the local dish: Aguadito. There is a unique Polleria (a really nice place to eat Aguadito) in Dogland, hence, this eatery is really selective with its customers. To eat in the Polleria, Chusky must solve the next task: Given D boxes, each one has all integer numbers between L_i and R_i (1 <= i <= D) inclusive, indicate the K-th lowest unique existing element. Because there is big queue waiting after Chusky, he has just some seconds to give the correct answer, otherwise he will not be able to eat in the Polleria and will eat some boiled potatoes that has at home (he does not like it too much) . +Help Chusky to eat an Aguadito. + +Input +===== + +The first line of the input contains a number T (1 <= T <= 100) indicating the number of test cases. Each test case follows the next format: +The first line of each test case contains a number D (1 <= D <= 100) representing the number of boxes Chusky receives, the second line contains a number K (1 <= K <= 10 ^ 15) representing the K- th number Chusky must guess, then D lines follows, each one in has two integers L_i and R_i (1 <= L_i <= R_i <= 10 ^ 15) representing that box i has all integers between L_i and R_i (1 <= i <= D) inclusive. + +Output +===== + +For each test case, print the K-th lowest number between all boxes. Print -1 if no K-th lowest number exists. + +Example +====== + +Input + +2 +3 +2 +3 6 +3 4 +11 13 +1 +7 +1 5 + +Output + +4 +-1 + +Explanation: + +For the first test case, the first box has numbers {3, 4, 5, 6}, the second one has {3, 4} and the last one has {11, 13}, then all existing numbers are {3, 4 , 5, 6, 11, 13} and the 2nd lowest number is 4. In the second case the box has numbers {1, 2, 3, 4, 5}, thus there is no 7th lowest element. + diff --git a/chusky_hunger/solution.cpp b/chusky_hunger/solution.cpp new file mode 100644 index 0000000..4a65e79 --- /dev/null +++ b/chusky_hunger/solution.cpp @@ -0,0 +1,75 @@ +#include +//#define DEBUG +using namespace std; +typedef vector < int > vi; +typedef pair < long long int, long long int > pii; +typedef vector < pii > vii; +typedef long long int i64; +int d; +i64 k; +bool byPairs(pii left, pii right) +{ + if(left.first != right.first) + return left.first < right.first; + return left.second < right.second; +} +i64 sol(vii &nums) +{ + sort(nums.begin(), nums.end(), byPairs); + + i64 ans = -1ll; + i64 last = -1ll; + int i = 0; + while(k>0ll && i < (int)nums.size()) + { + if(last < nums[i].first) // no overlap + { + i64 len = nums[i].second - nums[i].first + 1ll; +#ifdef DEBUG + + cout< " <>d>>k; + vii nums = vii(); + for(int i = 0; i < d; i++) + { + pii x; + cin>>x.first>>x.second; + nums.push_back(x); + } + cout<< sol(nums) < Date: Tue, 8 Oct 2019 22:30:43 -0500 Subject: [PATCH 064/109] Added word frequency problem --- Word_Frequency/question.txt | 7 +++++++ Word_Frequency/solution.js | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 Word_Frequency/question.txt create mode 100644 Word_Frequency/solution.js diff --git a/Word_Frequency/question.txt b/Word_Frequency/question.txt new file mode 100644 index 0000000..fd684eb --- /dev/null +++ b/Word_Frequency/question.txt @@ -0,0 +1,7 @@ +Given a text, find the frequency of all the words in it and print the words that are duplicates: +"Work hard and play hard and have fun at work." + +answer: +hard +work +and \ No newline at end of file diff --git a/Word_Frequency/solution.js b/Word_Frequency/solution.js new file mode 100644 index 0000000..41665f1 --- /dev/null +++ b/Word_Frequency/solution.js @@ -0,0 +1,22 @@ +function printDuplicates(inputText){ + var frequenceCountMap = {}; + var inputs = inputText.split(' '); + for(var ii = 0, len = inputs.length; ii < len; ii++){ + var word = inputs[ii]; + if(frequenceCountMap[word]){ + frequenceCountMap[word] += 1; + }else{ + frequenceCountMap[word] = 1; + } + } + + for(var key in frequenceCountMap){ + if(frequenceCountMap[key] > 1){ + console.log(key); + } + } +} + +var inputVal = "Work hard and play hard and have fun at work."; + +printDuplicates(inputVal); \ No newline at end of file From 9157d24097faf3fb2c02cac280671d08ed9ad4c2 Mon Sep 17 00:00:00 2001 From: hrishit biswas Date: Thu, 10 Oct 2019 11:47:52 +0530 Subject: [PATCH 065/109] Added Bytelandian Gold coins --- Bytelandian-gold-coins/instructions.txt | 27 +++++++++++++++++++++++++ Bytelandian-gold-coins/solution.cpp | 17 ++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 Bytelandian-gold-coins/instructions.txt create mode 100644 Bytelandian-gold-coins/solution.cpp diff --git a/Bytelandian-gold-coins/instructions.txt b/Bytelandian-gold-coins/instructions.txt new file mode 100644 index 0000000..74c2c86 --- /dev/null +++ b/Bytelandian-gold-coins/instructions.txt @@ -0,0 +1,27 @@ +In Byteland they have a very strange monetary system. + +Each Bytelandian gold coin has an integer number written on it. A coin n can be exchanged in a bank into three coins: n/2, n/3 and n/4. But these numbers are all rounded down (the banks have to make a profit). + +You can also sell Bytelandian coins for American dollars. The exchange rate is 1:1. But you can not buy Bytelandian coins. + +You have one gold coin. What is the maximum amount of American dollars you can get for it? +Input + +The input will contain several test cases (not more than 10). Each testcase is a single line with a number n, 0 <= n <= 1 000 000 000. It is the number written on your coin. +Output + +For each test case output a single line, containing the maximum amount of American dollars you can make. + +Example + +Input: +12 +2 + +Output: +13 +2 + +You can change 12 into 6, 4 and 3, and then change these into $6+$4+$3 = $13. +If you try changing the coin 2 into 3 smaller coins, you will get 1, 0 and 0, and later you can get no more than $1 out of them. +It is better just to change the 2 coin directly into $2. diff --git a/Bytelandian-gold-coins/solution.cpp b/Bytelandian-gold-coins/solution.cpp new file mode 100644 index 0000000..aebf1b2 --- /dev/null +++ b/Bytelandian-gold-coins/solution.cpp @@ -0,0 +1,17 @@ +#include +using namespace std; +map dp; +long long optcoins(int n){ + if(n<12) + return n; + if(dp.count(n)) + return dp[n]; + dp[n]=optcoins(n/2)+optcoins(n/3)+optcoins(n/4); + return dp[n]; +} +int main(){ + int x; + while(scanf("%d",&x)!=EOF) + printf("%lld\n",optcoins(x)); + return 0; +} From 5262e5a04be85a342de0cd3a922b844d460593f6 Mon Sep 17 00:00:00 2001 From: hrishit biswas Date: Thu, 10 Oct 2019 11:53:31 +0530 Subject: [PATCH 066/109] Added Philosophers Stone --- Philosophers_Stone/question.txt | 30 ++++++++++++++++++++++++++++++ Philosophers_Stone/solution.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 Philosophers_Stone/question.txt create mode 100644 Philosophers_Stone/solution.cpp diff --git a/Philosophers_Stone/question.txt b/Philosophers_Stone/question.txt new file mode 100644 index 0000000..f2474d3 --- /dev/null +++ b/Philosophers_Stone/question.txt @@ -0,0 +1,30 @@ + + +One of the secret chambers in Hogwarts is full of philosopher’s stones. The floor of the chamber is covered by h Ă— w square tiles, where there are h rows of tiles from front (first row) to back (last row) and w columns of tiles from left to right. Each tile has 1 to 100 stones on it. Harry has to grab as many philosopher’s stones as possible, subject to the following restrictions: + + He starts by choosing any tile in the first row, and collects the philosopher’s stones on that tile. Then, he moves to a tile in the next row, collects the philosopher’s stones on the tile, and so on until he reaches the last row. + When he moves from one tile to a tile in the next row, he can only move to the tile just below it or diagonally to the left or right. + +Given the values of h and w, and the number of philosopher’s stones on each tile, write a program to compute the maximum possible number of philosopher’s stones Harry can grab in one single trip from the first row to the last row. +Input + +The first line consists of a single integer T, the number of test cases. In each of the test cases, the first line has two integers. The first integer h (1 <= h <= 100) is the number of rows of tiles on the floor. The second integer w (1 <= w <= 100) is the number of columns of tiles on the floor. Next, there are h lines of inputs. The i-th line of these, specifies the number of philosopher’s stones in each tile of the i-th row from the front. Each line has w integers, where each integer m (0 <= m <= 100) is the number of philosopher’s stones on that tile. The integers are separated by a space character. +Output + +The output should consist of T lines, (1 <= T <= 100), one for each test case. Each line consists of a single integer, which is the maximum possible number of philosopher’s stones Harry can grab, in one single trip from the first row to the last row for the corresponding test case. +Example + +Input: +1 +6 5 +3 1 7 4 2 +2 1 3 1 1 +1 2 2 1 8 +2 2 1 5 3 +2 1 4 4 4 +5 2 7 5 1 + +Output: +32 + +//7+1+8+5+4+7=32 diff --git a/Philosophers_Stone/solution.cpp b/Philosophers_Stone/solution.cpp new file mode 100644 index 0000000..f3cc8e7 --- /dev/null +++ b/Philosophers_Stone/solution.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; +int main(void) +{ + int t; + cin>>t; + while(t--) + { + int r,c; + cin>>r>>c; + int arr[r][c+2]={0}; + arr[0][c+1]=0; + + for(int i=0;i>arr[i][j]; + + for(int i=r-2;i>=0;i--) + for(int j=1;j<=c;j++) + arr[i][j]+=max((arr[i+1][j-1]),max(arr[i+1][j],arr[i+1][j+1])); + + int max = INT_MIN; + for(int i=1;i<=c;i++) + if(arr[0][i]>max) + max = arr[0][i]; + + cout< Date: Thu, 10 Oct 2019 09:51:55 +0200 Subject: [PATCH 067/109] added bubble_sort_c --- bubble_sort_c/question.txt | 2 ++ bubble_sort_c/solution/bubble_sort.c | 23 +++++++++++++++++++++++ bubble_sort_c/solution/bubble_sort.h | 5 +++++ bubble_sort_c/solution/main.c | 12 ++++++++++++ bubble_sort_c/solution/print_array.c | 10 ++++++++++ 5 files changed, 52 insertions(+) create mode 100644 bubble_sort_c/question.txt create mode 100644 bubble_sort_c/solution/bubble_sort.c create mode 100644 bubble_sort_c/solution/bubble_sort.h create mode 100644 bubble_sort_c/solution/main.c create mode 100644 bubble_sort_c/solution/print_array.c diff --git a/bubble_sort_c/question.txt b/bubble_sort_c/question.txt new file mode 100644 index 0000000..bd6c83d --- /dev/null +++ b/bubble_sort_c/question.txt @@ -0,0 +1,2 @@ +Make a C program to bubble sort this array of integers (smallest to biggest): {303, -909, 101, 42, 0, 42, 21, 1, 2} +Expected result => {-909, 0, 1, 2, 21. 42, 42, 101, 303} diff --git a/bubble_sort_c/solution/bubble_sort.c b/bubble_sort_c/solution/bubble_sort.c new file mode 100644 index 0000000..8f7ab02 --- /dev/null +++ b/bubble_sort_c/solution/bubble_sort.c @@ -0,0 +1,23 @@ +#include "bubble_sort.h" + +void swap_values(int *a, int *b) +{ + int buffer = *a; + *a = *b; + *b = buffer; +} + +int *bubble_sort(int *arr, size_t arr_len) +{ + size_t i = 0; + + while (i++ < arr_len) + { + if (arr[i] < arr[i-1]) + { + swap_values(&arr[i], &arr[i-1]); + i = 0; + } + } + return(arr); +} diff --git a/bubble_sort_c/solution/bubble_sort.h b/bubble_sort_c/solution/bubble_sort.h new file mode 100644 index 0000000..4e69c28 --- /dev/null +++ b/bubble_sort_c/solution/bubble_sort.h @@ -0,0 +1,5 @@ +#include +#include + +int *bubble_sort(int *arr, size_t arr_len); +void print_array(int *arr, size_t arr_len); diff --git a/bubble_sort_c/solution/main.c b/bubble_sort_c/solution/main.c new file mode 100644 index 0000000..9616442 --- /dev/null +++ b/bubble_sort_c/solution/main.c @@ -0,0 +1,12 @@ +#include "bubble_sort.h" + +int main(void) +{ + int to_sort[] = {303, -909, 101, 42, 0, 42, 21, 1, 2}; + size_t arr_len = sizeof(to_sort) / sizeof(to_sort[0]); + int *sorted = bubble_sort(to_sort, arr_len); + + print_array(sorted, arr_len); + + return(EXIT_SUCCESS); +} diff --git a/bubble_sort_c/solution/print_array.c b/bubble_sort_c/solution/print_array.c new file mode 100644 index 0000000..39c130a --- /dev/null +++ b/bubble_sort_c/solution/print_array.c @@ -0,0 +1,10 @@ +#include "bubble_sort.h" + +void print_array(int *arr, size_t arr_len) +{ + size_t i; + + printf("Sorted array:\n"); + for (i = 0; i < arr_len; i++) + printf("%d\n", arr[i]); +} From 4e500b08e2eb4c0564a967657c6543061ebd8909 Mon Sep 17 00:00:00 2001 From: saksham Date: Thu, 10 Oct 2019 19:42:29 +0530 Subject: [PATCH 068/109] Added question-name --- .../insertion_sort.cpp | 182 ++++++++++++++++++ Insertion_sort_using_classes/problem.txt | 7 + 2 files changed, 189 insertions(+) create mode 100644 Insertion_sort_using_classes/insertion_sort.cpp create mode 100644 Insertion_sort_using_classes/problem.txt diff --git a/Insertion_sort_using_classes/insertion_sort.cpp b/Insertion_sort_using_classes/insertion_sort.cpp new file mode 100644 index 0000000..8aaa360 --- /dev/null +++ b/Insertion_sort_using_classes/insertion_sort.cpp @@ -0,0 +1,182 @@ +#include +using namespace std; + +/* Hi I am using my own class to use in insertion sort function*/ + +template +class LinearList{ + private: + int MaxSize; + Item *element; // 1D dynamic array + int len; + public: + /* Default constructor. + * Should create an empty list that not contain any elements*/ + LinearList() + { + element=nullptr; + len=0; + }; + + /* This constructor should create a list containing MaxSize elements. You can intialize the elements with any values.*/ + LinearList(const int& MaxListSize) + { + MaxSize=MaxListSize; + element = new Item[MaxSize]; + len=0; + + }; + + /* Destructor. + * Must free all the memory contained by the list */ + ~LinearList(){}; + + /* Indexing operator. + * It should behave the same way array indexing does. i.e, + * LinearList L; + * L[0] should refer to the first element; + * L[1] to the second element and so on. + * */ + Item& operator[](const int& i) + { + return element[i]; + }; //return i'th element of list + + /* Returns true if the list is empty, false otherwise. + * */ + bool isEmpty() + { + if(len==0) + { + return true; + } + else + { + return false; + } + }; + + /* Returns the actual length (number of elements) in the list. + * */ + int length() + { + return len; + }; + + /* Returns the maximum size of the list. + * */ + int maxSize() + { + return maxSize; + }; + + /* Returns the k-th element of the list. + * */ + Item returnListElement(const int k) + { + return element[k-1]; + }; + /* Set x to the k-th element and + * return true if k-th element is present otherwise return false. + * */ + bool find(const int k, Item& x) + { + if(x==element[k-1]) + { + return true; + } + else + { + + return false; + } + }; + + /* Search for x and + * return the position if found, else return 0. + * */ + int search(Item& x) + { + for(int i=0;ik;i--) + { + element[i]=element[i-1]; + } + element[k]=x; + len=len+1; + }; + + +}; + +//insertion sort function +void insertionSort(LinearList& A) + { + int i,j,temp,len; + i=j=0; + len=A.length(); + j=len; + for(i=1;i-1;j--) + { + if(temp> n; + LinearList l(100); + + for(i=0;i> temp; + l.insert(i,temp); + } + insertionSort(l); + for(i=0;i Date: Fri, 11 Oct 2019 15:08:48 +0530 Subject: [PATCH 069/109] Mislove Has Lost an Array Added a new problem with the solution --- Question.txt | Bin 0 -> 1692 bytes Solution.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 Question.txt create mode 100644 Solution.cpp diff --git a/Question.txt b/Question.txt new file mode 100644 index 0000000000000000000000000000000000000000..6abcaf90baa35bd5d28c5f804e8e59cd5f2d315b GIT binary patch literal 1692 zcmb7^&2H0B5QS%r#5-7QDx?B((m(~uf(?QNV#5w~;j~U0;l#xb&^|S90Gw|oBRkND zqUgr=-kCXb=I73@pYLsDy*1X_H><6%E3526-^w=r-&v>qt?x@a_V2{MKOV&iz1Eic zXLqfAFU+l0Ag*-3751f8CmB`?`>H#yV|26 z)wF|V+2|l&gk_eM$+EKsIsk9qsB@my9;ovC&hT|2%wz! zI@5hb9a1!MP3+8GNuE7R&c?VKJMx=D=%=#Bx)zs8TzY2#=giwaTPj5EH(t3D+5Wr# z;P*egriyQRCol3DyjuCqNsyhHvDWrQkyOen*>Ckni$>u&?hV9`F z8|wBaR>tyo--1Zr&h2#f%IMJ7svq6dc|BsjMC^eabsZ)Sy&ID$>)hLCuPc-3*84KE z7hM`}GtdgX0eWDiZ{#_1JIE`$8OdYvGJ6;Pb_(?mGm2Rg^BEi}wm%J!$MlNHGQ1up taL&kg;&Ls#tvyk#xur9C+Y>*1a9L;|ok{Y-C1cCbMaG<&9kiTE{u|k>5~lzF literal 0 HcmV?d00001 diff --git a/Solution.cpp b/Solution.cpp new file mode 100644 index 0000000..4cf529c --- /dev/null +++ b/Solution.cpp @@ -0,0 +1,26 @@ +#include +using namespace std; +int main() +{ + long long int i,mini=1,mine=0,maxi=1,maxo=0,n,s,e; + cin>>n>>s>>e; + + for(i=1;i<=s-1;i++) + { + mini=2*mini; + mine+=mini; + } +mine+=n-s+1; + +for(i=1;i<=e-1;i++) +{ + maxi=2*maxi; + maxo+=maxi; +} +maxo+=1; + + +maxo+=(n-e)*(maxi); +cout< Date: Fri, 11 Oct 2019 15:14:32 +0530 Subject: [PATCH 070/109] Create Question.txt --- Mislove Has Lost an Array/Question.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Mislove Has Lost an Array/Question.txt diff --git a/Mislove Has Lost an Array/Question.txt b/Mislove Has Lost an Array/Question.txt new file mode 100644 index 0000000..23182ac --- /dev/null +++ b/Mislove Has Lost an Array/Question.txt @@ -0,0 +1,17 @@ +Mislove had an array a1, a2, ⋯, an of n positive integers, but he has lost it. He only remembers the following facts about it: + +1)The number of different numbers in the array is not less than l and is not greater than r. +2)For each array's element ai either ai=1 or ai is even and there is a number ai/2 in the array. + +For example, if n=5, l=2, r=3 then an array could be [1,2,2,4,4] or [1,1,1,1,2]; but it couldn't be [1,2,2,4,8] because this array contains 4 different numbers; it couldn't be [1,2,2,3,3] because 3 is odd and isn't equal to 1; and it couldn't be [1,1,2,2,16] because there is a number 16 in the array but there isn't a number 16/2=8. + +According to these facts, he is asking you to count the minimal and the maximal possible sums of all elements in an array. + +Input-1 +4 2 2 +Output +5 7 +Input-2 +5 1 5 +Output +5 31 From 12e12e485d14e4d5fc800fbe89ae0904b98131a5 Mon Sep 17 00:00:00 2001 From: Aditya Jain <31203114+Adityajain732@users.noreply.github.com> Date: Fri, 11 Oct 2019 15:15:20 +0530 Subject: [PATCH 071/109] Create Solution.cpp --- Mislove Has Lost an Array/Solution.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Mislove Has Lost an Array/Solution.cpp diff --git a/Mislove Has Lost an Array/Solution.cpp b/Mislove Has Lost an Array/Solution.cpp new file mode 100644 index 0000000..841440f --- /dev/null +++ b/Mislove Has Lost an Array/Solution.cpp @@ -0,0 +1,26 @@ +#include +using namespace std; +int main() +{ + long long int i,mini=1,mine=0,maxi=1,maxo=0,n,s,e; + cin>>n>>s>>e; + + for(i=1;i<=s-1;i++) + { + mini=2*mini; + mine+=mini; + } +mine+=n-s+1; + +for(i=1;i<=e-1;i++) +{ + maxi=2*maxi; + maxo+=maxi; +} +maxo+=1; + + +maxo+=(n-e)*(maxi); +cout< Date: Fri, 11 Oct 2019 15:17:17 +0530 Subject: [PATCH 072/109] Delete Question.txt --- Question.txt | Bin 1692 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 Question.txt diff --git a/Question.txt b/Question.txt deleted file mode 100644 index 6abcaf90baa35bd5d28c5f804e8e59cd5f2d315b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1692 zcmb7^&2H0B5QS%r#5-7QDx?B((m(~uf(?QNV#5w~;j~U0;l#xb&^|S90Gw|oBRkND zqUgr=-kCXb=I73@pYLsDy*1X_H><6%E3526-^w=r-&v>qt?x@a_V2{MKOV&iz1Eic zXLqfAFU+l0Ag*-3751f8CmB`?`>H#yV|26 z)wF|V+2|l&gk_eM$+EKsIsk9qsB@my9;ovC&hT|2%wz! zI@5hb9a1!MP3+8GNuE7R&c?VKJMx=D=%=#Bx)zs8TzY2#=giwaTPj5EH(t3D+5Wr# z;P*egriyQRCol3DyjuCqNsyhHvDWrQkyOen*>Ckni$>u&?hV9`F z8|wBaR>tyo--1Zr&h2#f%IMJ7svq6dc|BsjMC^eabsZ)Sy&ID$>)hLCuPc-3*84KE z7hM`}GtdgX0eWDiZ{#_1JIE`$8OdYvGJ6;Pb_(?mGm2Rg^BEi}wm%J!$MlNHGQ1up taL&kg;&Ls#tvyk#xur9C+Y>*1a9L;|ok{Y-C1cCbMaG<&9kiTE{u|k>5~lzF From 98ede3e688977704efafc42e2afcf5e1fea41dda Mon Sep 17 00:00:00 2001 From: Aditya Jain <31203114+Adityajain732@users.noreply.github.com> Date: Fri, 11 Oct 2019 15:17:43 +0530 Subject: [PATCH 073/109] Delete Solution.cpp --- Solution.cpp | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 Solution.cpp diff --git a/Solution.cpp b/Solution.cpp deleted file mode 100644 index 4cf529c..0000000 --- a/Solution.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include -using namespace std; -int main() -{ - long long int i,mini=1,mine=0,maxi=1,maxo=0,n,s,e; - cin>>n>>s>>e; - - for(i=1;i<=s-1;i++) - { - mini=2*mini; - mine+=mini; - } -mine+=n-s+1; - -for(i=1;i<=e-1;i++) -{ - maxi=2*maxi; - maxo+=maxi; -} -maxo+=1; - - -maxo+=(n-e)*(maxi); -cout< Date: Sat, 12 Oct 2019 00:24:54 +0530 Subject: [PATCH 074/109] add sudoku code --- SudokuSolver/Question.txt | 20 +++++++ SudokuSolver/sudokuSolver.cpp | 100 ++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 SudokuSolver/Question.txt create mode 100755 SudokuSolver/sudokuSolver.cpp diff --git a/SudokuSolver/Question.txt b/SudokuSolver/Question.txt new file mode 100644 index 0000000..eadd651 --- /dev/null +++ b/SudokuSolver/Question.txt @@ -0,0 +1,20 @@ +Given a partially filled NxN 2D array, the goal is to assign digits (from 1 to 9) +to the empty cells (cells assigned O value) so that every row, column,and subgrid +of size 3Ă—3 contains exactly one instance of the digits from 1 to 9. We provide the +value of N and a partially filled sudoku as input. + +Sample Input: +4 +3 4 1 0 0 2 0 0 0 0 2 0 0 1 4 3 + +Sample Output: +============== +3 4 1 0 +0 2 0 0 +0 0 2 0 +0 1 4 3 +============== +3 4 1 2 +1 2 3 4 +4 3 2 1 +2 1 4 3 diff --git a/SudokuSolver/sudokuSolver.cpp b/SudokuSolver/sudokuSolver.cpp new file mode 100755 index 0000000..e088400 --- /dev/null +++ b/SudokuSolver/sudokuSolver.cpp @@ -0,0 +1,100 @@ +#include +#include +using namespace std; + +void print2D(int arr[][20], int M, int N) { + for (int i = 0; i < M; ++i) { + for (int j = 0; j < N; ++j) { + cout << arr[i][j] << " "; + } + cout << endl; + } +} + +bool myfixed[20][20] = {}; + +void input2D_soduku(int arr[][20], int M, int N) +{ + for (int i = 0; i < M; ++i) + { + for (int j = 0; j < N; ++j) + { + cin >> arr[i][j]; + if (arr[i][j] != 0) myfixed[i][j] = true; //so that our entry does not change + } + } +} + +bool canPlace(int board[][20], int N, int x, int y, int num) +{ + //check along row && col + for (int i = 0; i < N; ++i) + { + if (board[x][i] == num) return false; //check along row + if (board[i][y] == num) return false; //check along col + } + + //check in the box + int rootN = sqrt(N); + int boxRow = x / rootN; + int boxCol = y / rootN; + int startRow = boxRow * rootN; + int startCol = boxCol * rootN; + + for (int r = startRow; r < startRow + rootN; ++r) + { + for (int c = startCol; c < startCol + rootN; ++c) + { + if (board[r][c] == num) return false; + } + } + + return true; +} + + +bool solveSudoku(int board[][20], int N, int x, int y) +{ + if (x == N && y == 0) return true; //we have reached row 4 ---->sudoku over + + if (y == N) return solveSudoku(board, N, x + 1, 0);//stop y to go to column4-->goto nxt row + + if (myfixed[x][y]) return solveSudoku(board, N, x , y + 1); + + for (int num = 1; num <= N; ++num) + { + if (canPlace(board, N, x, y, num) == true) + { + board[x][y] = num; + bool isSuccessful = solveSudoku(board, N, x , y + 1); //recursion for nxt columns + if (isSuccessful) return true; + else board[x][y] = 0; + } + } + return false; +} + +int main() +{ + int board[20][20] = {}; + + int N; + cin >> N; + input2D_soduku(board, N, N); + for(int i=0;i>board[i][j]; + } + } + cout << "==============\n"; + + print2D(board, N, N); + + cout << "==============\n"; + + solveSudoku(board, N, 0, 0); + + print2D(board, N, N); + +} + From e476f2bc45b933621a6664394486b13575547f79 Mon Sep 17 00:00:00 2001 From: Muskan Goyal Date: Sat, 12 Oct 2019 00:30:31 +0530 Subject: [PATCH 075/109] fixed --- .DS_Store | Bin 12292 -> 12292 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/.DS_Store b/.DS_Store index fa501d182026124fbe10cdd77cce43730721611a..6b19b25ca24f98b36d6bffae549b9dbe6dc5f790 100644 GIT binary patch delta 29 hcmZokXi3-ULYy6d4gn#7y$9!55fQd From b45f9080f318bb6832aaa2dac64293e38bf05758 Mon Sep 17 00:00:00 2001 From: Rishabhdeep Singh Date: Sun, 13 Oct 2019 01:39:18 +0530 Subject: [PATCH 076/109] Added POLYMUL from SPOJ --- PolyMul/question.txt | 31 ++++++++++++++++ PolyMul/solution.cpp | 86 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 PolyMul/question.txt create mode 100644 PolyMul/solution.cpp diff --git a/PolyMul/question.txt b/PolyMul/question.txt new file mode 100644 index 0000000..2d08f19 --- /dev/null +++ b/PolyMul/question.txt @@ -0,0 +1,31 @@ +Sam and Dean fight the supernatural creatures to protect the humans. Now they have come across a creature called the Vedala, which are always found in pairs. Each vedala can be represented by a polynomial. Both the Vedalas need to be killed at once or else they can't be killed. They can be killed only by using the product of the two polynomials representing the two Vedala. Help Sam and Dean find the product of the polynomials fast, so they can do thier work. + +Input + +First line contains an integer T (≤ 10), number of test cases. +Each test case will have n (n ≤ 10000), maximum degree of the polynomials on the first line. + +Next two lines will have n+1 space separated integers each representing the coeffiecients of first and second polynomials respectively. + +All input coefficients values are <=1000. + +Output +For each test case ouput a line of 2n space seperated integers indicating coefficients of the polynomial created after multiplication. + + +Example +Input: +2 +2 +1 2 3 +3 2 1 +2 +1 0 1 +2 1 0 + +Output: +3 8 14 8 3 +2 1 2 1 0 + + + diff --git a/PolyMul/solution.cpp b/PolyMul/solution.cpp new file mode 100644 index 0000000..f439663 --- /dev/null +++ b/PolyMul/solution.cpp @@ -0,0 +1,86 @@ +#include + +using namespace std; + +typedef long long int LL; +typedef vector VLL; +typedef std::complex CD; + +#define PB push_back +#define F first +#define s second +#define SZ(x) x.size() +#define ALL(a) std::begin(a), std::end(a) +#define IN_REP int _t; cin >> _t ; while(_t--) +#define IOS ios::sync_with_stdio(false);cin.tie(NULL) +#define FOR(i, a, b) for(int i=(a);i<(b);i++) +#define REP(i, n) FOR(i,0,n) +const double PI = acos(-1); +typedef std::valarray CArray; + +// Cooley–Tukey FFT (in-place) +void fft(CArray &x) { + // const size_t N = x.size(); + int N = SZ(x); + if (N <= 1) return; + + // divide + CArray even = x[std::slice(0, N / 2, 2)]; + CArray odd = x[std::slice(1, N / 2, 2)]; + + // conquer + fft(even); + fft(odd); + + // combine + // for (size_t k = 0; k < N/2; ++k){ + for (int k = 0; k < N / 2; ++k) { + CD t = std::polar(1.0, -2 * PI * k / N) * odd[k]; + x[k] = even[k] + t; + x[k + N / 2] = even[k] - t; + } +} + +// inverse fft (in-place) +void ifft(CArray &x) { + // conjugate the complex numbers + x = x.apply(std::conj); + + // forward fft + fft(x); + + // conjugate the complex numbers again + x = x.apply(std::conj); + + // scale the numbers + x /= x.size(); +} + +int main() { + IOS; + IN_REP { + int n; + cin >> n; + n++; // Given in question + int size = 2 * (1 << int(ceil(log2(n)))); + + CArray x(size), y(size); + FOR(i, size - n, size) cin >> x[i]; + fft(x); + FOR(i, size - n, size) cin >> y[i]; + fft(y); + + CArray res(size); + res = x * y; + ifft(res); + VLL ans; + REP(i, size - 1) { + ans.PB(round(res[i].real())); + } + for (int i = size - 1 - (2 * n - 1); i < size - 1; i++) { + cout << ans[i] << " "; + } + cout << endl; + } + return 0; +} From 270e0ab39788d6bb9007e7d3f235f2cc22494410 Mon Sep 17 00:00:00 2001 From: Rishabhdeep Singh Date: Sun, 13 Oct 2019 02:15:22 +0530 Subject: [PATCH 077/109] Added Strange Food Chain --- Strange_Food_Chain/question.txt | 37 ++++++++++++++++++++++++ Strange_Food_Chain/solution.cpp | 51 +++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 Strange_Food_Chain/question.txt create mode 100644 Strange_Food_Chain/solution.cpp diff --git a/Strange_Food_Chain/question.txt b/Strange_Food_Chain/question.txt new file mode 100644 index 0000000..ae9b410 --- /dev/null +++ b/Strange_Food_Chain/question.txt @@ -0,0 +1,37 @@ +There are 3 kinds of animals A,B and C. A can eat B,B can eat C,C can eat A. It's interesting,isn't it? + +Now we have n animals,numbered from 1 to n. Each of them is one of the 3 kinds of animals:A,B,C. + +Today Mary tells us k pieces of information about these n animals. Each piece has one of the two forms below: + +1 x y: It tells us the kind of x and y are the same. +2 x y: It tells us x can eat y. +Some of these k pieces are true,some are false. The piece is false if it satisfies one of the 3 conditions below, otherwise it's true. + +X or Y in this piece is larger than n. +This piece tells us X can eat X. +This piece conflicts to some true piece before. +Input +The first line contains a single integer t.t blocks follow. + +To every block,the first line contains two integers n(1<=n<=50000) and k (1<=k<=100000). k lines follow,each contains 3 positive integers D(1<=D<=2),X,Y,separated by single spaces. + + +Output +t lines,each contains a single integer - the number of false pieces in the corresponding block. + + +Example +Sample input: +1 +100 7 +1 101 1 +2 1 2 +2 2 3 +2 3 3 +1 1 3 +2 3 1 +1 5 5 + +Sample output: +3 diff --git a/Strange_Food_Chain/solution.cpp b/Strange_Food_Chain/solution.cpp new file mode 100644 index 0000000..ba8dc5b --- /dev/null +++ b/Strange_Food_Chain/solution.cpp @@ -0,0 +1,51 @@ +#include +#include + +using namespace std; + +const int N = 5e4 + 10; + +int n, k; +int par[N], lab[N]; + +int anc(int u) { + if (u == par[u]) return u; + int tmp = par[u]; + par[u] = anc(par[u]); + lab[u] = lab[tmp] + lab[u]; + return par[u]; +} + +int main() { + // freopen("input.in", "r", stdin); +// freopen("output.out", "w", stdout); + + int test; scanf("%d", &test); + while (test--) { + scanf("%d%d", &n, &k); + for (int i = 1; i <= n; ++i) { + par[i] = i; + lab[i] = 0; + } + int answer = 0; + while (k--) { + int t, x, y; scanf("%d%d%d", &t, &x, &y); + if (x > n || y > n) { answer++; continue; } + int px = anc(x), py = anc(y); + t--; + if (px == py) { + int tmp = (lab[x] - lab[y]) % 3; if (tmp < 0) tmp += 3; + if (tmp != t) answer++; + } else { + par[px] = py; + int i = (lab[x] - lab[y] - t) % 3; + lab[px] = i < 0 ? -i : -i + 3; + } + } + printf("%d\n", answer); + } + + return 0; +} + + From f37b68bb189374f3fad46460880b617c1c140e7e Mon Sep 17 00:00:00 2001 From: Rishabhdeep Singh Date: Sun, 13 Oct 2019 02:18:22 +0530 Subject: [PATCH 078/109] Added Chocolate Spoj Problem --- Chocolate_SPOJ/question.txt | 41 ++++++++ Chocolate_SPOJ/solution.java | 182 +++++++++++++++++++++++++++++++++++ 2 files changed, 223 insertions(+) create mode 100644 Chocolate_SPOJ/question.txt create mode 100644 Chocolate_SPOJ/solution.java diff --git a/Chocolate_SPOJ/question.txt b/Chocolate_SPOJ/question.txt new file mode 100644 index 0000000..8f45eef --- /dev/null +++ b/Chocolate_SPOJ/question.txt @@ -0,0 +1,41 @@ +We are given a bar of chocolate composed of m*n square pieces. One should break the chocolate into single squares. Parts of the chocolate may be broken along the vertical and horizontal lines as indicated by the broken lines in the picture. + +A single break of a part of the chocolate along a chosen vertical or horizontal line divides that part into two smaller ones. Each break of a part of the chocolate is charged a cost expressed by a positive integer. This cost does not depend on the size of the part that is being broken but only depends on the line the break goes along. Let us denote the costs of breaking along consecutive vertical lines with x1, x2, ..., xm-1 and along horizontal lines with y1, y2, ..., yn-1. + +The cost of breaking the whole bar into single squares is the sum of the successive breaks. One should compute the minimal cost of breaking the whole chocolate into single squares. + + +For example, if we break the chocolate presented in the picture first along the horizontal lines, and next each obtained part along vertical lines then the cost of that breaking will be y1+y2+y3+4*(x1+x2+x3+x4+x5). + +Task +Write a program that for each test case: + +Reads the numbers x1, x2, ..., xm-1 and y1, y2, ..., yn-1 +Computes the minimal cost of breaking the whole chocolate into single squares, writes the result. +Input +One integer in the first line, stating the number of test cases, followed by a blank line. There will be not more than 20 tests. + +For each test case, at the first line there are two positive integers m and n separated by a single space, 2 <= m,n <= 1000. In the successive m-1 lines there are numbers x1, x2, ..., xm-1, one per line, 1 <= xi <= 1000. In the successive n-1 lines there are numbers y1, y2, ..., yn-1, one per line, 1 <= yi <= 1000. + +The test cases will be separated by a single blank line. + +Output +For each test case : write one integer - the minimal cost of breaking the whole chocolate into single squares. + + +Example +Input: +1 + +6 4 +2 +1 +3 +1 +4 +4 +1 +2 + +Output: +42 diff --git a/Chocolate_SPOJ/solution.java b/Chocolate_SPOJ/solution.java new file mode 100644 index 0000000..f04b8c2 --- /dev/null +++ b/Chocolate_SPOJ/solution.java @@ -0,0 +1,182 @@ +import java.io.OutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.util.Arrays; +import java.io.BufferedWriter; +import java.io.Writer; +import java.io.OutputStreamWriter; +import java.util.InputMismatchException; +import java.io.IOException; +import java.io.InputStream; + +/** + * Built using CHelper plug-in + * Actual solution is at the top + * + * @author Rishabhdeep Singh + */ +public class Main { + public static void main(String[] args) { + InputStream inputStream = System.in; + OutputStream outputStream = System.out; + InputReader in = new InputReader(inputStream); + OutputWriter out = new OutputWriter(outputStream); + MultipleTestcases solver = new MultipleTestcases(); + int testCount = Integer.parseInt(in.next()); + for (int i = 1; i <= testCount; i++) + solver.solve(i, in, out); + out.close(); + } + + static class MultipleTestcases { + public void solve(int testNumber, InputReader in, OutputWriter out) { + int n = in.nextInt(); + int m = in.nextInt(); + --n; + --m; + int[] x = in.nextIntArray(n); + int[] y = in.nextIntArray(m); + int s1 = 0, s2 = 0; + for (int i = 0; i < n; i++) { + s1 += x[i]; + } + for (int i = 0; i < m; i++) { + s2 += y[i]; + } + Arrays.sort(x); + Arrays.sort(y); + int ans = s1 + s2; + for (int i = n - 1, j = m - 1; i >= 0 && j >= 0; ) { + if (y[j] >= x[i]) { + ans += s1; + s2 -= y[j]; + --j; + } else { + ans += s2; + s1 -= x[i]; + --i; + } + } + out.println(ans); + } + + } + + static class OutputWriter { + private final PrintWriter writer; + + public OutputWriter(OutputStream outputStream) { + writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); + } + + public OutputWriter(Writer writer) { + this.writer = new PrintWriter(writer); + } + + public void close() { + writer.close(); + } + + public void println(int i) { + writer.println(i); + } + + } + + static class InputReader { + private InputStream stream; + private byte[] buf = new byte[1024]; + private int curChar; + private int numChars; + private InputReader.SpaceCharFilter filter; + + public InputReader(InputStream stream) { + this.stream = stream; + } + + public int read() { + if (numChars == -1) { + throw new InputMismatchException(); + } + if (curChar >= numChars) { + curChar = 0; + try { + numChars = stream.read(buf); + } catch (IOException e) { + throw new InputMismatchException(); + } + if (numChars <= 0) { + return -1; + } + } + return buf[curChar++]; + } + + public int nextInt() { + int c = read(); + while (isSpaceChar(c)) { + c = read(); + } + int sgn = 1; + if (c == '-') { + sgn = -1; + c = read(); + } + int res = 0; + do { + if (c < '0' || c > '9') { + throw new InputMismatchException(); + } + res *= 10; + res += c - '0'; + c = read(); + } while (!isSpaceChar(c)); + return res * sgn; + } + + public String nextString() { + int c = read(); + while (isSpaceChar(c)) { + c = read(); + } + StringBuilder res = new StringBuilder(); + do { + if (Character.isValidCodePoint(c)) { + res.appendCodePoint(c); + } + c = read(); + } while (!isSpaceChar(c)); + return res.toString(); + } + + public boolean isSpaceChar(int c) { + if (filter != null) { + return filter.isSpaceChar(c); + } + return isWhitespace(c); + } + + public static boolean isWhitespace(int c) { + return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; + } + + public String next() { + return nextString(); + } + + public int[] nextIntArray(int n) { + int[] array = new int[n]; + for (int i = 0; i < n; ++i) array[i] = nextInt(); + return array; + } + + public interface SpaceCharFilter { + public boolean isSpaceChar(int ch); + + } + + } +} + From 2cc9056c974acf2041f1f93da64b1a7020837211 Mon Sep 17 00:00:00 2001 From: ShivamMangale Date: Tue, 15 Oct 2019 04:43:31 +0530 Subject: [PATCH 079/109] Added White-Sheet --- White-Sheet/White-Sheet.txt | 54 +++++++++++++++++++++++++++++++++++ White-Sheet/code.cpp | 57 +++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 White-Sheet/White-Sheet.txt create mode 100644 White-Sheet/code.cpp diff --git a/White-Sheet/White-Sheet.txt b/White-Sheet/White-Sheet.txt new file mode 100644 index 0000000..e865c86 --- /dev/null +++ b/White-Sheet/White-Sheet.txt @@ -0,0 +1,54 @@ +There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0,0), and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates (x1,y1), and the top right — (x2,y2). +After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are (x3,y3), and the top right — (x4,y4). Coordinates of the bottom left corner of the second black sheet are (x5,y5), and the top right — (x6,y6). + + +Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets. +Input +The first line of the input contains four integers x1,y1,x2,y2 (0≤x1 +using namespace std; + +typedef long long int ll; + + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(0); + cout.tie(0); + + ll x11,x12,y11,y12; + ll x21,x22,y21,y22; + ll x31,x32,y31,y32; + + ll area = 0; + + cin>>x11>>y11>>x12>>y12; + cin>>x21>>y21>>x22>>y22; + cin>>x31>>y31>>x32>>y32; + + area = abs(x11-x12)*abs(y11-y12); + x21 = max(x11,x21); + y21 = max(y11,y21); + x22 = min(x12,x22); + y22 = min(y12,y22); + x31 = max(x11,x31); + y31 = max(y11,y31); + x32 = min(x12,x32); + y32 = min(y12,y32); + ll a1,a2,b1,b2; + if(x21 < x22 && y21 < y22) area -= abs(x21-x22)*abs(y21-y22); + if(x31 < x32 && y31 < y32) area -= abs(x31-x32)*abs(y31-y32); + if((x21x31) || (x21x32)) + { + if((y21 < y31 && y22 > y31) || (y21 < y32 && y22 > y32)) + { + ll narea = 0; + + } + } + + a1 = max(x21,x31); + b1 = max(y21,y31); + a2 = min(x22,x32); + b2 = min(y22,y32); + + if(a1 < a2 && b1 < b2) area += abs(a2-a1)*abs(b2-b1); + + if(area > 0) cout<<"YES\n"; + else cout<<"NO\n"; + + return 0; +} \ No newline at end of file From db7026c74cc9b89b8f112622b0e13c91418714d5 Mon Sep 17 00:00:00 2001 From: rohitsh16 Date: Tue, 15 Oct 2019 09:38:25 +0530 Subject: [PATCH 080/109] added prime_subsequence --- Prime_subsequence/question.txt | 10 +++++++++ Prime_subsequence/solution.cpp | 41 ++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 Prime_subsequence/question.txt create mode 100644 Prime_subsequence/solution.cpp diff --git a/Prime_subsequence/question.txt b/Prime_subsequence/question.txt new file mode 100644 index 0000000..b91d65a --- /dev/null +++ b/Prime_subsequence/question.txt @@ -0,0 +1,10 @@ + +Given a sequence of prime numbers A1,A2,…,AN. This sequence has exactly 2N subsequences. +A subsequence of A is good if it does not contain any two identical numbers; in particular, the empty sequence is good. + +You to find the number of good subsequences which contain at most K numbers. +This number could be very large, so compute it modulo 1,000,000,007. + +Constraints: +1≤K≤N≤105 +2≤Ai≤8,000 for each valid i diff --git a/Prime_subsequence/solution.cpp b/Prime_subsequence/solution.cpp new file mode 100644 index 0000000..09cc920 --- /dev/null +++ b/Prime_subsequence/solution.cpp @@ -0,0 +1,41 @@ +#include +using namespace std; +int main(){ + ios_base::sync_with_stdio(false); + int n,k;cin>>n>>k; + int a[n];long long int mod=1000000007; + int max=0; + for(int i=0;i>a[i]; + if(a[i]>max) + max=a[i]; + } + long int f[max+1]; + memset(f,0,sizeof(f)); + for(int i=0;iv; + for(int i=0;i<=max;i++) + if(f[i]) + v.push_back(f[i]); + long int l=v.size(); + k=k>l?l:k; + long int dpans[k+1][l],val; + val=v[0]+1; + memset(dpans,0,sizeof(dpans)); + dpans[0][0]=1; + dpans[1][0]=val; + long int total=0; + for(int i=2;i<=k;i++) + dpans[i][0]=val; + for(int i=1;i Date: Tue, 15 Oct 2019 11:50:57 +0530 Subject: [PATCH 081/109] Delete PATTERN2.CPP --- PATTERN2.CPP | 81 ---------------------------------------------------- 1 file changed, 81 deletions(-) delete mode 100644 PATTERN2.CPP diff --git a/PATTERN2.CPP b/PATTERN2.CPP deleted file mode 100644 index 18a269d..0000000 --- a/PATTERN2.CPP +++ /dev/null @@ -1,81 +0,0 @@ -#include -#include -void main() -{ - clrscr(); - int n,i,j,k; - cout<<"Enter Value Of n: "; - cin>>n; - int space=n-1; - for(i=1; i<=n;i++) - { - cout<=1;k--) - { - cout<<" "; - } - space--; - for(j=1; j<=i; j++) - cout<=1; j--) - cout<>n; - space=n-1; - for(i=1; i<=n;i++) - { - cout<=1;k--) - cout<<" "; - for (j=1; j<=(2*i)-1; j++) - cout<<'*'; - space--; - } - space=1; - for (i=1; i<=n-1; i++) - { - cout<=1; k--) - cout<<" "; - for(j=1;j<=2*(n-i)-1;j++) - cout<<'*'; - space++; - } - getch(); -} - -/* -Enter Value Of n: 5 - - - 1 - 121 - 12321 - 1234321 -123454321 - -Enter Value Of n: 6 - - * - *** - ***** - ******* - ********* -*********** - ********* - ******* - ***** - *** - * - -*/ - - - - - - From b3c2adcd63aa8b49b1c0804515d225cf7fae9e5c Mon Sep 17 00:00:00 2001 From: Kashinath Patekar <42115482+helix026@users.noreply.github.com> Date: Wed, 16 Oct 2019 06:41:47 +0530 Subject: [PATCH 082/109] Add O(sqrt n) solution in JS --- Is prime?/solution.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Is prime?/solution.js diff --git a/Is prime?/solution.js b/Is prime?/solution.js new file mode 100644 index 0000000..292a44a --- /dev/null +++ b/Is prime?/solution.js @@ -0,0 +1,12 @@ +function isPrime(n) { + if(n<2) return false + let prime = true + for (let i = 2; i*i<= n; i++) { + if( n%i == 0) { + prime = false + break + } + } + + return prime +} From 58f8a6a1c5365937c70b23c9e517bb4dd7b263d0 Mon Sep 17 00:00:00 2001 From: Lakshay Agarwal Date: Wed, 16 Oct 2019 20:44:02 +0530 Subject: [PATCH 083/109] Added triplet_problem --- triplet_problem/question.txt | 1 + triplet_problem/solution.c | 48 ++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 triplet_problem/question.txt create mode 100644 triplet_problem/solution.c diff --git a/triplet_problem/question.txt b/triplet_problem/question.txt new file mode 100644 index 0000000..b1417a8 --- /dev/null +++ b/triplet_problem/question.txt @@ -0,0 +1 @@ +Find a triplet such that sum of two equals to third element in an array. diff --git a/triplet_problem/solution.c b/triplet_problem/solution.c new file mode 100644 index 0000000..69ac10c --- /dev/null +++ b/triplet_problem/solution.c @@ -0,0 +1,48 @@ +#include + +void sort(int a[],int); +void findtriplet(int a[],int n) +{ + sort(a,n); + for(int k=n-1;k>=0;k--) + { + int i=0,j=k-1; + while(i (a[i]+a[j])) + i++; + else + j--; + } + } + printf("No such triplet exists\n"); +} + +void sort(int a[],int n) +{ + for(int i=0;i a[j+1]) + { + int t; + t = a[j]; + a[j] = a[j+1]; + a[j+1] = t; + } + } + } +} + +int main() +{ + int a[9] = {5,32,1,7,10,50,15,21,2}; + findtriplet(a,9); + return 0; +} From 92f40d9cd7eb6091cf2e7d29c8bbae665e2b2a18 Mon Sep 17 00:00:00 2001 From: ameerasherin98 <56751656+ameerasherin98@users.noreply.github.com> Date: Sat, 19 Oct 2019 12:21:10 +0530 Subject: [PATCH 084/109] Update Source1.cpp --- Check_String_Palindrome/Source1.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Check_String_Palindrome/Source1.cpp b/Check_String_Palindrome/Source1.cpp index 0fdda1d..8585e70 100644 --- a/Check_String_Palindrome/Source1.cpp +++ b/Check_String_Palindrome/Source1.cpp @@ -3,6 +3,7 @@ using namespace std; +//This is a function that returns a boolean value, after checking the string. bool checkStringPallindrome(string inputString); bool checkStringPallindrome(string inputString) { @@ -13,10 +14,11 @@ bool checkStringPallindrome(string inputString) { } return true; } -int main() { +void main() { - string input; - getline(cin, input); + clrscr(); //this inbuild function clears the screen + string input; //the string to check whether its palindrome or not + getline(cin, input); if (checkStringPallindrome(input)) { cout << "true" << endl; } @@ -24,6 +26,5 @@ int main() { cout << "false" << endl; } - system("pause"); - return 1; -} \ No newline at end of file + getch(); +} From d2481e91162e6fc647191e2cf36184ad1a552793 Mon Sep 17 00:00:00 2001 From: pmm3 Date: Sat, 19 Oct 2019 14:04:38 -0400 Subject: [PATCH 085/109] Add Buy and sell stock atmost k times for a maximum profit --- .../buyAndSellStock.py | 40 +++++++++++++++++++ .../problem-statement.txt | 9 +++++ 2 files changed, 49 insertions(+) create mode 100644 Buy-and-Sell-Stock-for-Maximum-Profit/buyAndSellStock.py create mode 100644 Buy-and-Sell-Stock-for-Maximum-Profit/problem-statement.txt diff --git a/Buy-and-Sell-Stock-for-Maximum-Profit/buyAndSellStock.py b/Buy-and-Sell-Stock-for-Maximum-Profit/buyAndSellStock.py new file mode 100644 index 0000000..729a2a8 --- /dev/null +++ b/Buy-and-Sell-Stock-for-Maximum-Profit/buyAndSellStock.py @@ -0,0 +1,40 @@ +''' +Ref: https://www.geeksforgeeks.org/maximum-profit-by-buying-and-selling-a-share-at-most-k-times/ + +''' +# Python program to maximize the profit +# by doing at most k transactions +# given stock prices for n days + +# Function to find out maximum profit by +# buying & selling a share atmost k times +# given stock price of n days +def maxProfit(prices, n, k): + + # Bottom-up DP approach + profit = [[0 for i in range(k + 1)] + for j in range(n)] + + # Profit is zero for the first + # day and for zero transactions + for i in range(1, n): + + for j in range(1, k + 1): + max_so_far = 0 + + for l in range(i): + max_so_far = max(max_so_far, prices[i] - + prices[l] + profit[l][j - 1]) + + profit[i][j] = max(profit[i - 1][j], max_so_far) + + return profit[n - 1][k] + +# Driver code +k = 2 +prices = [10, 22, 5, 75, 65, 80] +n = len(prices) + +print("Maximum profit is:", + maxProfit(prices, n, k)) + diff --git a/Buy-and-Sell-Stock-for-Maximum-Profit/problem-statement.txt b/Buy-and-Sell-Stock-for-Maximum-Profit/problem-statement.txt new file mode 100644 index 0000000..3d45433 --- /dev/null +++ b/Buy-and-Sell-Stock-for-Maximum-Profit/problem-statement.txt @@ -0,0 +1,9 @@ +Ref: https://www.geeksforgeeks.org/maximum-profit-by-buying-and-selling-a-share-at-most-k-times/ + + +In share trading, a buyer buys shares and sells on a future date. Given the stock price of n days, the trader is allowed to make at most k transactions, where a new transaction can only start after the previous transaction is complete, find out the maximum profit that a share trader could have made. + +There are various versions of the problem. If we are allowed to buy and sell only once, then we can use Maximum difference between two elements algorithm. If we are allowed to make at most 2 transactions, we can follow approach discussed here. + +In this case, we are only allowed to make at max k transactions. The problem can be solved by using dynamic programming. + From 7a9946b9edb1e70db112d2dd3b389ad63bde982e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bermudes=20Viana?= Date: Sun, 20 Oct 2019 12:42:04 -0300 Subject: [PATCH 086/109] Add txt file --- .../Biggest_Sum_5_Consecutives_Integers | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Biggest_Sum_5_Consecutives_Integers/Biggest_Sum_5_Consecutives_Integers diff --git a/Biggest_Sum_5_Consecutives_Integers/Biggest_Sum_5_Consecutives_Integers b/Biggest_Sum_5_Consecutives_Integers/Biggest_Sum_5_Consecutives_Integers new file mode 100644 index 0000000..b526a8c --- /dev/null +++ b/Biggest_Sum_5_Consecutives_Integers/Biggest_Sum_5_Consecutives_Integers @@ -0,0 +1,19 @@ +What's the biggest sum you can get from adding 5 consecutives integers in a array? + +Example: + Array = [1, 3, -2, 4, -9, 1, 4, 7] + Possibles Sums: + 1 + 3 + (-2) + 4 + (-9) = -3 + 3 + (-2) + 4 + (-9) + 1 = -3 + (-2) + 4 + (-9) + 1 + 4 = -2 + 4 + (-9) + 1 + 4 + 7 = 7 + + So the biggest Sum is 7. + +What's the biggest sum of 5 consecutives integers of the array below? + +Array = [1, 3, -5, 8, -9, 13, -2, -3, 8, 4, 3, 6, 1, 2, -2, -4, 8, -4, 1, 8, 2, 1, 3, 1, 2, 3, + 7, 8, -9, 5, 4, 3, 2, 4, 1, 2, 6, 6, 7, -15, 9, 7, 8, 16, -10, 1, 2, 6, 6, 4, -5, 2, 2 + 3, 6, 7, 8, 1, 2, 3, 3, 4, 5, 6, 1, -5,7, -9, 10, 1, 3, 4, 8, 7, 6, 4, 1, 1, 2, 3, 1] + +PS: There may or may not have different sequences that has the same sum. From f58a99ef90389f588fef76c1f0daff93d75d0b3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bermudes=20Viana?= Date: Sun, 20 Oct 2019 12:42:25 -0300 Subject: [PATCH 087/109] add solution --- .../solution.c | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Biggest_Sum_5_Consecutives_Integers/solution.c diff --git a/Biggest_Sum_5_Consecutives_Integers/solution.c b/Biggest_Sum_5_Consecutives_Integers/solution.c new file mode 100644 index 0000000..086bd3f --- /dev/null +++ b/Biggest_Sum_5_Consecutives_Integers/solution.c @@ -0,0 +1,23 @@ +#include +#include + +int main(){ + int i; + int size = 81; //SIZE OF THE ARRAY + int sum; + int biggestSum; + int array[] = {1, 3, -5, 8, -9, 13, -2, -3, 8, 4, 3, 6, 1, 2, -2, -4, 8, -4, 1, 8, 2, 1, 3, 1, 2, 3, 7, 8, -9, 5, 4, 3, 2, 4, 1, 2, 6, 6, 7, -15, 9, 7, 8, 16, -10, 1, 2, 6, 6, 4, -5, 2, 2, 3, 6, 7, 8, 1, 2, 3, 3, 4, 5, 6, 1, -5, 7, -9, 10, 1, 3, 4, 8, 7, 6, 4, 1, 1, 2, 3, 1}; + + //FIRST SUM + sum = array[0] + array[1] + array[2] + array[3] + array[4]; + biggestSum = sum; + + //OTHER SUMS + for(i = 1; i < (size - 4); i++){ //THERE ARE (size - 4) POSSIBLE SUMS, BUT WE ALREADY MADE 1, SO i STARTS AT 1 + sum = sum - array[i - 1] + array[i + 4]; //REMOVE THE FIRST OF THE OLD SUM, AND ADD THE NEW INTEGER + if(sum > biggestSum){ + biggestSum = sum; + } + } + printf("biggestSum = %d\n", biggestSum); //PRINT THE RESULT +} \ No newline at end of file From d30a57161eb6131f8cdcab07a1b440a752b00ba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bermudes=20Viana?= Date: Sun, 20 Oct 2019 13:00:01 -0300 Subject: [PATCH 088/109] Added txt --- CollatzConjecture/CollatzConjecture.txt | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 CollatzConjecture/CollatzConjecture.txt diff --git a/CollatzConjecture/CollatzConjecture.txt b/CollatzConjecture/CollatzConjecture.txt new file mode 100644 index 0000000..799a6b3 --- /dev/null +++ b/CollatzConjecture/CollatzConjecture.txt @@ -0,0 +1,24 @@ +Collatz Conjecture + +The Collatz Conjecture says that if you take any number and follow the following steps, you will never be stuck in a loop. + +If the number is even -> number = number/2; +If the number is odd -> number = 3*number + 1; + +If you continue to do this, at some point your number will be equal to 1. + +Example: number = 26 + 1 Step - number = 26/2 = 13 + 2 Step - number = 13*3 + 1 = 40 + 3 Step - number = 40/2 = 20 + 4 Step - number = 20/2 = 10 + 5 Step - number = 10/2 = 5 + 6 Step - number = 3*5 + 1 = 16 + 7 Step - number = 16/2 = 8 + 8 Step - number = 8/2 = 4 + 9 Step - number = 4/2 = 2 + 10 Step - number = 2/2 = 1 + +For the number 26, 10 steps are needed, create a solution that calculates the number of steps for a given N number, +and the biggest value the number had during the steps. + From a30538d52aee7d760262b5e8bf244ead343d91f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bermudes=20Viana?= Date: Sun, 20 Oct 2019 13:00:40 -0300 Subject: [PATCH 089/109] Added .c --- CollatzConjecture/solution.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 CollatzConjecture/solution.c diff --git a/CollatzConjecture/solution.c b/CollatzConjecture/solution.c new file mode 100644 index 0000000..600e64a --- /dev/null +++ b/CollatzConjecture/solution.c @@ -0,0 +1,23 @@ +#include +#include + +int main(){ + long int N = 26; //CALCULATING FOR N = 26 + long int biggestValue = 0; + long int steps = 0; + + while(N != 1){ + if(N%2 == 0){ + N = N/2; + }else{ + N = N*3 + 1; + } + if(N>biggestValue){ + biggestValue = N; + } + steps++; + } + + printf("Number of Steps: %ld BiggestValue: %ld", steps, biggestValue); + +} \ No newline at end of file From a810f74458ca08fcfe32d2b06f180657e86d82eb Mon Sep 17 00:00:00 2001 From: Ayman Azzam Date: Tue, 22 Oct 2019 23:40:46 +0200 Subject: [PATCH 090/109] Industrial Nim is added --- Industrial Nim/Industrial_Nim.cpp | 35 +++++++++++++++++++++++++++++++ Industrial Nim/Industrial_Nim.txt | 29 +++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 Industrial Nim/Industrial_Nim.cpp create mode 100644 Industrial Nim/Industrial_Nim.txt diff --git a/Industrial Nim/Industrial_Nim.cpp b/Industrial Nim/Industrial_Nim.cpp new file mode 100644 index 0000000..680db05 --- /dev/null +++ b/Industrial Nim/Industrial_Nim.cpp @@ -0,0 +1,35 @@ +#include +using namespace std; + +vector vec; +bool nim() /* return true if the first player will win */ +{ + long long x=0; + for(int i=0;i0; +} + +long long f(long long n) /* n&3 equivalent to n%4 */ +{ + long long x=n&3; + if(x==0) return n; if(x==1) return 1; + if(x==2) return n+1; if(x==3) return 0; +} + + + +int main() +{ + long long n,x,m; + cin>>n; + while(n--) + { + cin>>x>>m; + vec.push_back(f(x+m-1)^f(x-1)); + } + if(nim()) + cout<<"tolik"< Date: Thu, 1 Oct 2020 01:54:53 +0530 Subject: [PATCH 091/109] Create question 1408A.txt --- Circle Coloring/question 1408A.txt | 82 ++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Circle Coloring/question 1408A.txt diff --git a/Circle Coloring/question 1408A.txt b/Circle Coloring/question 1408A.txt new file mode 100644 index 0000000..d412d68 --- /dev/null +++ b/Circle Coloring/question 1408A.txt @@ -0,0 +1,82 @@ + CIRCLE COLORING + time limit per test1 second + memory limit per test256 megabytes + inputstandard input + outputstandard output + +You are given three sequences: a1,a2,…,an; b1,b2,…,bn; c1,c2,…,cn. + +For each i, ai≠bi, ai≠ci, bi≠ci. + +Find a sequence p1,p2,…,pn, that satisfy the following conditions: + +piâ{ai,bi,ci} +pi≠p(imodn)+1. +In other words, for each element, you need to choose one of the three possible values, such that no two adjacent elements (where we consider elements i,i+1 adjacent for i Date: Thu, 1 Oct 2020 01:55:32 +0530 Subject: [PATCH 092/109] Create 1408A.cpp --- Circle Coloring/1408A.cpp | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Circle Coloring/1408A.cpp diff --git a/Circle Coloring/1408A.cpp b/Circle Coloring/1408A.cpp new file mode 100644 index 0000000..d526a08 --- /dev/null +++ b/Circle Coloring/1408A.cpp @@ -0,0 +1,52 @@ +#include + +using namespace std; + +int main() +{ + while() + { + int n; + cin>>n; + std::vector a(n), b(n), c(n), ans; + + for(int i=0; i>a[i]; + } + for(int i=0; i>b[i]; + } + for(int i=0; i>c[i]; + } + ans.push_back(a[0]); + + for(int i=1; i Date: Sat, 10 Oct 2020 00:11:34 +0530 Subject: [PATCH 093/109] Delete problem.txt --- Is prime?/problem.txt | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 Is prime?/problem.txt diff --git a/Is prime?/problem.txt b/Is prime?/problem.txt deleted file mode 100644 index 7357bc2..0000000 --- a/Is prime?/problem.txt +++ /dev/null @@ -1,9 +0,0 @@ -Implement a function that determines if a given positive integer is a prime or not. - -Example - -For n = 47, the output should be -isPrime(n) = true; - -For n = 4, the output should be -isPrime(n) = false; \ No newline at end of file From b9bea4939ab98176de3c427768ce1d5d585c2f84 Mon Sep 17 00:00:00 2001 From: Parth Chauhan <35137224+chauhanparth210@users.noreply.github.com> Date: Sat, 10 Oct 2020 00:11:56 +0530 Subject: [PATCH 094/109] Delete solution.hs --- Is prime?/solution.hs | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Is prime?/solution.hs diff --git a/Is prime?/solution.hs b/Is prime?/solution.hs deleted file mode 100644 index 05b33bc..0000000 --- a/Is prime?/solution.hs +++ /dev/null @@ -1 +0,0 @@ -isPrime n = length (filter (==0) (map (mod n) [1..n])) == 2 \ No newline at end of file From 127d349a6c00a08cad6cd3d046335a875635608d Mon Sep 17 00:00:00 2001 From: Parth Chauhan <35137224+chauhanparth210@users.noreply.github.com> Date: Sat, 10 Oct 2020 00:12:16 +0530 Subject: [PATCH 095/109] Delete solution.js --- Is prime?/solution.js | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 Is prime?/solution.js diff --git a/Is prime?/solution.js b/Is prime?/solution.js deleted file mode 100644 index 292a44a..0000000 --- a/Is prime?/solution.js +++ /dev/null @@ -1,12 +0,0 @@ -function isPrime(n) { - if(n<2) return false - let prime = true - for (let i = 2; i*i<= n; i++) { - if( n%i == 0) { - prime = false - break - } - } - - return prime -} From b2c35f11b247233f554e07508d9a1087a676420a Mon Sep 17 00:00:00 2001 From: chauhanparth210 <00chauhanparth@gmail.com> Date: Sat, 10 Oct 2020 00:20:07 +0530 Subject: [PATCH 096/109] is_prime is added by stellarbeam and jonathan-sh --- is_prime/problem.txt | 9 +++++++++ is_prime/solution.hs | 1 + is_prime/solution.js | 12 ++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 is_prime/problem.txt create mode 100644 is_prime/solution.hs create mode 100644 is_prime/solution.js diff --git a/is_prime/problem.txt b/is_prime/problem.txt new file mode 100644 index 0000000..3ca919e --- /dev/null +++ b/is_prime/problem.txt @@ -0,0 +1,9 @@ +Implement a function that determines if a given positive integer is a prime or not. + +Example + +For n = 47, the output should be +isPrime(n) = true; + +For n = 4, the output should be +isPrime(n) = false; diff --git a/is_prime/solution.hs b/is_prime/solution.hs new file mode 100644 index 0000000..05b33bc --- /dev/null +++ b/is_prime/solution.hs @@ -0,0 +1 @@ +isPrime n = length (filter (==0) (map (mod n) [1..n])) == 2 \ No newline at end of file diff --git a/is_prime/solution.js b/is_prime/solution.js new file mode 100644 index 0000000..714c8f7 --- /dev/null +++ b/is_prime/solution.js @@ -0,0 +1,12 @@ +function isPrime(n) { + if(n<2) return false + let prime = true + for (let i = 2; i*i<= n; i++) { + if( n%i == 0) { + prime = false + break + } + } + + return prime +} \ No newline at end of file From 2f1de3ea241e1608127bcd994d01f12e2ab0fbb3 Mon Sep 17 00:00:00 2001 From: chauhanparth210 <00chauhanparth@gmail.com> Date: Sat, 10 Oct 2020 00:35:49 +0530 Subject: [PATCH 097/109] topic wise folders --- {FCFS => Algorithm/FCFS}/fcfs.py | 0 {FCFS => Algorithm/FCFS}/question.txt | 0 .../Floodfill}/Problem_statement.txt | 56 ++--- .../Floodfill}/solution.java | 106 +++++----- .../Floodfill}/solution.py | 0 .../Josephus's Problem}/josephus.java | 0 .../Josephus's Problem}/question.txt | 0 .../Kadane's Algorithm}/kadane.c | 72 +++---- .../Kadane's Algorithm}/kadane.cpp | 0 .../Kadane's Algorithm}/kadane.py | 0 .../Kadane's Algorithm}/problem.txt | 10 +- .../hot_potato}/hot_potato.cpp | 0 .../hot_potato}/question.txt | 0 {nQueen => Algorithm/nQueen}/Question.txt | 0 {nQueen => Algorithm/nQueen}/nQueen.cpp | 180 ++++++++-------- .../Biggest_Sum_5_Consecutives_Integers | 0 .../solution.c | 44 ++-- .../Circle Coloring}/1408A.cpp | 0 .../Circle Coloring}/question 1408A.txt | 0 .../Lily's Homework}/Question.txt | 20 +- .../Lily's Homework}/solution.py | 52 ++--- .../Mislove Has Lost an Array}/Question.txt | 0 .../Mislove Has Lost an Array}/Solution.cpp | 0 .../Omar and Candies}/Problem Statement.txt | 0 .../Omar and Candies}/Solution.c | 0 .../Philosophers_Stone}/question.txt | 0 .../Philosophers_Stone}/solution.cpp | 0 .../Phone price}/solution.cpp | 0 .../Phone price}/statement.txt | 0 .../Sieve of Eratosthenes}/Question.txt | 0 .../Sieve of Eratosthenes}/Solution.cpp | 0 {TRUEDARE => Array/TRUEDARE}/QUESTION.txt | 0 {TRUEDARE => Array/TRUEDARE}/SOLUTION.txt | 0 .../White-Sheet}/White-Sheet.txt | 106 +++++----- {White-Sheet => Array/White-Sheet}/code.cpp | 0 .../triplet_problem}/question.txt | 0 .../triplet_problem}/solution.c | 0 .../SudokuSolver}/Question.txt | 0 .../SudokuSolver}/sudokuSolver.cpp | 200 +++++++++--------- .../Armstrong No}/armstrongnum.c | 0 .../Average}/Average-Question.txt | 0 {Average => Basic Math/Average}/Solution.cpp | 0 .../counting.txt | 0 .../Counting-Change-Combinations}/solution.js | 0 .../Divisibility_Check}/Question.txt | 0 .../Divisibility_Check}/Solution.cpp | 0 .../Problem Description.txt | 4 +- .../Divisible Sum Pairs}/solution.js | 24 +-- .../Fizz Buzz}/c#_solution.cs | 0 .../Fizz Buzz}/dart_solution.dart | 26 +-- .../Fizz Buzz}/fizzbuzz.c | 24 +-- .../Fizz Buzz}/fizzbuzz.cpp | 32 +-- .../Fizz Buzz}/instructions.txt | 0 .../Fizz Buzz}/javascript_solution.js | 0 .../Fizz Buzz}/php_solution.php | 0 .../Fizz Buzz}/python_solution.py | 0 .../Fizz Buzz}/ruby_solution.rb | 0 {is_prime => Basic Math/Is prime}/problem.txt | 2 +- {is_prime => Basic Math/Is prime}/solution.hs | 0 {is_prime => Basic Math/Is prime}/solution.js | 2 +- .../Least_Common_Multiple}/LCM.cbl | 0 .../Least_Common_Multiple}/Problem.txt | 0 .../Octal Decimal Calculator.txt | 16 +- .../OctalDecimalCalculator.java | 86 ++++---- .../.idea/Odd or Even Game.iml | 0 .../Odd or Even Game}/.idea/misc.xml | 0 .../Odd or Even Game}/.idea/modules.xml | 0 .../Odd or Even Game}/.idea/vcs.xml | 0 .../Odd or Even Game}/.idea/workspace.xml | 0 .../Odd or Even Game}/OddEvenGame.txt | 0 .../Odd or Even Game}/oddEvenGame.py | 0 {PROXY => Basic Math/PROXY}/question.txt | 0 {PROXY => Basic Math/PROXY}/solution.cpp | 0 .../Prime_gen}/Prime Generator(prime_gen) | 0 .../Prime_gen}/prime_gen.cpp | 0 .../Save the Prisoner!}/question.txt | 0 .../Save the Prisoner!}/solution.cpp | 0 .../Sherlock-and-the-beast-problem.md | 0 .../Sherlock-and-the-beast}/solution.cpp | 130 ++++++------ .../The Additionator}/The Additionator.txt | 0 .../The Additionator}/solution.java | 0 .../The Prime Game}/Problem_statement.txt | 16 +- .../The Prime Game}/Solution.py | 24 +-- .../problem_statement.txt | 0 .../when to take medicine_answer.txt | 0 .../find_factorial_of_a_number.txt | 0 .../find_factorial_of_a_number}/solution.cpp | 0 .../Highly divisible triangular number.cpp | 0 .../project_euler problem12}/problem | 0 .../CollatzConjecture}/CollatzConjecture.txt | 0 .../CollatzConjecture}/solution.c | 44 ++-- .../EncoderProblem}/Encoder.java | 0 .../EncoderProblem}/problem.txt | 0 .../Leap Year}/instructions.txt | 0 .../Leap Year}/ruby_solution.rb | 0 .../Sleep_In}/sleep_in.py | 0 .../hacktoberfest-loop.txt | 0 .../infinity-hscktoberfest-loop.py | 0 .../problem statement.txt | 0 .../Aggressive Cows Spoj}/solution1.cpp | 0 .../Aggressive Cows Spoj}/solution2.cpp | 0 .../binary_search}/binary_search.txt | 0 .../binary_search}/bs.class | Bin .../binary_search}/bs.ctxt | 0 .../binary_search}/bs.java | 0 .../binary_search}/solution.cpp | 0 .../binary_search}/solution.py | 0 .../ZOMCAV}/ZOMCAV.txt | 0 .../ZOMCAV}/codechef.class | Bin .../ZOMCAV}/codechef.ctxt | 0 .../ZOMCAV}/codechef.java | 0 .../0-1 Knapsack Problem}/Question.txt | 0 .../0-1 Knapsack Problem}/Solution.c | 0 .../buyAndSellStock.py | 0 .../problem-statement.txt | 0 .../Bytelandian-gold-coins}/instructions.txt | 0 .../Bytelandian-gold-coins}/solution.cpp | 0 .../COINS}/Question.txt | 0 .../COINS}/Readme.md | 0 .../COINS}/Solution.cpp | 0 .../Min Steps to 1 Problem Statement.txt | 0 .../DP- Min Steps to 1}/minsteps.java | 0 .../Magic-Spells-LCS}/problem.txt | 0 .../Magic-Spells-LCS}/solution.cpp | 0 .../Max_Sum_Contiguous_Subarray}/Question.txt | 0 .../Max_Sum_Contiguous_Subarray}/Readme.md | 0 .../Max_Sum_Contiguous_Subarray}/Solution.cpp | 0 .../Maximize the product.txt | 0 .../Maximize the Product}/solution.cpp | 0 .../Maximum sum of digits}/code.cpp | 0 .../problem_statement.txt | 0 .../Maximum-Perimeter-Triangle-Problem | 0 .../Maximum-Perimeter-Triangle}/Solution.cpp | 0 .../Powerset}/powerset.js | 0 .../Powerset}/question.txt | 0 .../Prime_subsequence}/question.txt | 0 .../Prime_subsequence}/solution.cpp | 0 .../ROCK}/problem.txt | 0 {ROCK => Dynamic Programming/ROCK}/rock.cpp | 0 .../Rod cutting problem}/question.txt | 0 .../Rod cutting problem}/solution.java | 0 .../mailbox-question.txt | 0 .../solution.cpp | 0 .../Zero_Sum_SubArray}/question.txt | 0 .../Zero_Sum_SubArray}/solution.cpp | 0 .../alphacode}/problem_statement.txt | 0 .../alphacode}/solution.txt | 0 .../question.txt | 0 .../solution.cpp | 0 .../Problem_Statement.txt | 0 .../The_Coin_Change_Problem}/Solution.java | 0 .../Problem Statement.txt | 0 .../Solution.cpp | 0 {AAL => Patterns/AAL}/Aditya And Ladders.txt | 0 {AAL => Patterns/AAL}/x.cpp | 0 .../PatternPrinting}/README.md | 0 .../PatternPrinting}/sum.java | 70 +++--- .../SpiralMatrix}/problem.txt | 0 .../SpiralMatrix}/solution.cpp | 0 README.md | 17 +- .../Factorial using recursion.cpp | 0 .../Factorial using Recursion}/Question.txt | 0 .../Tower-of-Hanoi}/Hanoi.java | 0 .../Tower-of-Hanoi}/Tower of Hanoi.txt | 0 .../problem_statement.txt | 0 .../In search of an easy problem}/sol.cpp | 0 .../SGU_weeds_344}/weed.cpp | 0 .../SGU_weeds_344}/weed.txt | 0 .../Get Longest Sorted Sequence}/answer.py | 0 .../Get Longest Sorted Sequence}/problem.txt | 0 .../insertion_sort.cpp | 0 .../Insertion_sort_using_classes}/problem.txt | 0 .../Mergesort-JS}/mergeSort.js | 0 .../Mergesort-JS}/question.txt | 0 .../Merging_Two_Sorted_Array}/question.txt | 0 .../Merging_Two_Sorted_Array}/solution.cpp | 0 .../Mersort_In_C++}/mergeSort.cpp | 156 +++++++------- .../Mersort_In_C++}/mergesort.txt | 0 .../Quicksort-JS}/question.txt | 0 .../Quicksort-JS}/quickSort.js | 0 .../Quicksort-python}/Question.txt | 0 .../Quicksort-python}/algorithm.txt | 0 .../Quicksort-python}/quickSort.py | 0 .../bubble_sort_c}/question.txt | 0 .../bubble_sort_c}/solution/bubble_sort.c | 0 .../bubble_sort_c}/solution/bubble_sort.h | 0 .../bubble_sort_c}/solution/main.c | 0 .../bubble_sort_c}/solution/print_array.c | 0 .../Generate Parentheses}/Question.txt | 0 .../Generate Parentheses}/Solution | Bin .../Generate Parentheses}/Solution.cpp | 0 .../Street parade}/code.cpp | 0 .../Street parade}/problem_statement.txt | 0 .../AnagramChecking}/anagram_checking.py | 0 .../AnagramChecking}/anagram_checking.txt | 0 .../Arrangement_of_Queue}/Question.txt | 0 .../Arrangement_of_Queue}/README.md | 0 .../Arrangement_of_Queue}/Solution.py | 0 .../Cenit-Polar-Crypt}/Issue.txt | 0 .../Cenit-Polar-Crypt}/Solution.js | 0 .../Check_String_Palindrome}/Source1.cpp | 0 .../Check_String_Palindrome}/problem.txt | 0 {FANCY => String/FANCY}/problem.txt | 0 {FANCY => String/FANCY}/solution.py | 0 {Isograms => String/Isograms}/isograms.py | 0 .../Isograms}/problem_statement.txt | 0 .../Palindrome}/palindrome.c | 0 .../Palindrome}/question.txt | 0 .../Python_Palindrome}/PalindromeQues.txt | 0 .../Python_Palindrome}/solution.py | 0 .../Reverse string in place}/question.txt | 0 .../Reverse string in place}/solution.java | 0 .../ReverseChars}/ReverseChars.java | 50 ++--- .../ReverseChars}/problem.txt | 0 .../SplitString}/Question.txt | 0 .../SplitString}/Solution.cpp | 0 .../String_Permutation}/question.txt | 0 .../String_Permutation}/solution.cpp | 0 .../StrongPassword}/solution.py | 0 .../StrongPassword}/strongpasswordqn.txt | 0 .../Subsequences}/question.txt | 0 .../Subsequences}/subsequences.cpp | 54 ++--- .../The Reversed World}/Solution.cpp | 0 .../The Reversed World.txt | 0 .../ToyObsession}/problem.c | 0 .../ToyObsession}/solution.c | 0 .../Word_Frequency}/question.txt | 0 .../Word_Frequency}/solution.js | 0 {ginortS => String/ginortS}/Question.txt | 0 {ginortS => String/ginortS}/Solution.py | 0 .../size-of-tree-C++}/problem_statement.txt | 0 .../size-of-tree-C++}/sizeoftree.cpp | 0 {Acronym => Unknown/Acronym}/instructions.txt | 0 {Acronym => Unknown/Acronym}/ruby_solution.rb | 0 {CONTON => Unknown/CONTON}/QUESTION.txt | 0 {CONTON => Unknown/CONTON}/solution.c | 0 {Chefdil => Unknown/Chefdil}/ans.cpp | 0 {Chefdil => Unknown/Chefdil}/ques.txt | 0 .../Chocolate_SPOJ}/question.txt | 0 .../Chocolate_SPOJ}/solution.java | 0 .../Fair Rations}/Answer.cpp | 0 .../Fair Rations}/Problem Statement .txt | 0 .../Industrial Nim}/Industrial_Nim.cpp | 0 .../Industrial Nim}/Industrial_Nim.txt | 0 {Necklace => Unknown/Necklace}/solution.cpp | 0 {Necklace => Unknown/Necklace}/statement.pdf | Bin {PINS => Unknown/PINS}/problem.txt | 0 {PINS => Unknown/PINS}/solution.cpp | 0 {PolyMul => Unknown/PolyMul}/question.txt | 0 {PolyMul => Unknown/PolyMul}/solution.cpp | 0 .../Strange_Food_Chain}/question.txt | 0 .../Strange_Food_Chain}/solution.cpp | 0 {WATCHFB => Unknown/WATCHFB}/Main.class | Bin {WATCHFB => Unknown/WATCHFB}/Main.ctxt | 0 {WATCHFB => Unknown/WATCHFB}/Main.java | 0 {WATCHFB => Unknown/WATCHFB}/WATCHFB.txt | 0 .../chusky_adventurer}/problem_statement.txt | 0 .../chusky_adventurer}/solution.cpp | 0 .../chusky_hunger}/problem_statement.txt | 0 .../chusky_hunger}/solution.cpp | 0 .../chusky_nightgame}/problem_statement.txt | 0 .../chusky_nightgame}/solution.cpp | 0 .../coin-piles}/problem_statement.txt | 0 .../coin-piles}/solution.cpp | 0 264 files changed, 818 insertions(+), 805 deletions(-) rename {FCFS => Algorithm/FCFS}/fcfs.py (100%) rename {FCFS => Algorithm/FCFS}/question.txt (100%) rename {Floodfill => Algorithm/Floodfill}/Problem_statement.txt (97%) rename {Floodfill => Algorithm/Floodfill}/solution.java (95%) rename {Floodfill => Algorithm/Floodfill}/solution.py (100%) rename {Josephus's Problem => Algorithm/Josephus's Problem}/josephus.java (100%) rename {Josephus's Problem => Algorithm/Josephus's Problem}/question.txt (100%) rename {Kadane's Algorithm => Algorithm/Kadane's Algorithm}/kadane.c (95%) rename {Kadane's Algorithm => Algorithm/Kadane's Algorithm}/kadane.cpp (100%) rename {Kadane's Algorithm => Algorithm/Kadane's Algorithm}/kadane.py (100%) rename {Kadane's Algorithm => Algorithm/Kadane's Algorithm}/problem.txt (96%) rename {hot_potato => Algorithm/hot_potato}/hot_potato.cpp (100%) rename {hot_potato => Algorithm/hot_potato}/question.txt (100%) rename {nQueen => Algorithm/nQueen}/Question.txt (100%) rename {nQueen => Algorithm/nQueen}/nQueen.cpp (96%) mode change 100755 => 100644 rename {Biggest_Sum_5_Consecutives_Integers => Array/Biggest_Sum_5_Consecutives_Integers}/Biggest_Sum_5_Consecutives_Integers (100%) rename {Biggest_Sum_5_Consecutives_Integers => Array/Biggest_Sum_5_Consecutives_Integers}/solution.c (97%) rename {Circle Coloring => Array/Circle Coloring}/1408A.cpp (100%) rename {Circle Coloring => Array/Circle Coloring}/question 1408A.txt (100%) rename {Lily's Homework => Array/Lily's Homework}/Question.txt (98%) rename {Lily's Homework => Array/Lily's Homework}/solution.py (96%) rename {Mislove Has Lost an Array => Array/Mislove Has Lost an Array}/Question.txt (100%) rename {Mislove Has Lost an Array => Array/Mislove Has Lost an Array}/Solution.cpp (100%) rename {Omar and Candies => Array/Omar and Candies}/Problem Statement.txt (100%) rename {Omar and Candies => Array/Omar and Candies}/Solution.c (100%) rename {Philosophers_Stone => Array/Philosophers_Stone}/question.txt (100%) rename {Philosophers_Stone => Array/Philosophers_Stone}/solution.cpp (100%) rename {Phone price => Array/Phone price}/solution.cpp (100%) rename {Phone price => Array/Phone price}/statement.txt (100%) rename {Sieve of Eratosthenes => Array/Sieve of Eratosthenes}/Question.txt (100%) rename {Sieve of Eratosthenes => Array/Sieve of Eratosthenes}/Solution.cpp (100%) rename {TRUEDARE => Array/TRUEDARE}/QUESTION.txt (100%) rename {TRUEDARE => Array/TRUEDARE}/SOLUTION.txt (100%) rename {White-Sheet => Array/White-Sheet}/White-Sheet.txt (97%) rename {White-Sheet => Array/White-Sheet}/code.cpp (100%) rename {triplet_problem => Array/triplet_problem}/question.txt (100%) rename {triplet_problem => Array/triplet_problem}/solution.c (100%) rename {SudokuSolver => Backtracking/SudokuSolver}/Question.txt (100%) rename {SudokuSolver => Backtracking/SudokuSolver}/sudokuSolver.cpp (95%) mode change 100755 => 100644 rename {Armstrong No => Basic Math/Armstrong No}/armstrongnum.c (100%) rename {Average => Basic Math/Average}/Average-Question.txt (100%) rename {Average => Basic Math/Average}/Solution.cpp (100%) rename {Counting-Change-Combinations => Basic Math/Counting-Change-Combinations}/counting.txt (100%) rename {Counting-Change-Combinations => Basic Math/Counting-Change-Combinations}/solution.js (100%) rename {Divisibility_Check => Basic Math/Divisibility_Check}/Question.txt (100%) rename {Divisibility_Check => Basic Math/Divisibility_Check}/Solution.cpp (100%) rename {Divisible Sum Pairs => Basic Math/Divisible Sum Pairs}/Problem Description.txt (98%) rename {Divisible Sum Pairs => Basic Math/Divisible Sum Pairs}/solution.js (95%) rename {Fizz Buzz => Basic Math/Fizz Buzz}/c#_solution.cs (100%) rename {Fizz Buzz => Basic Math/Fizz Buzz}/dart_solution.dart (94%) rename {Fizz Buzz => Basic Math/Fizz Buzz}/fizzbuzz.c (95%) rename {Fizz Buzz => Basic Math/Fizz Buzz}/fizzbuzz.cpp (95%) rename {Fizz Buzz => Basic Math/Fizz Buzz}/instructions.txt (100%) rename {Fizz Buzz => Basic Math/Fizz Buzz}/javascript_solution.js (100%) rename {Fizz Buzz => Basic Math/Fizz Buzz}/php_solution.php (100%) rename {Fizz Buzz => Basic Math/Fizz Buzz}/python_solution.py (100%) rename {Fizz Buzz => Basic Math/Fizz Buzz}/ruby_solution.rb (100%) rename {is_prime => Basic Math/Is prime}/problem.txt (89%) rename {is_prime => Basic Math/Is prime}/solution.hs (100%) rename {is_prime => Basic Math/Is prime}/solution.js (99%) rename {Least_Common_Multiple => Basic Math/Least_Common_Multiple}/LCM.cbl (100%) rename {Least_Common_Multiple => Basic Math/Least_Common_Multiple}/Problem.txt (100%) rename {Octal Decimal Calculator => Basic Math/Octal Decimal Calculator}/Octal Decimal Calculator.txt (97%) rename {Octal Decimal Calculator => Basic Math/Octal Decimal Calculator}/OctalDecimalCalculator.java (96%) rename {Odd or Even Game => Basic Math/Odd or Even Game}/.idea/Odd or Even Game.iml (100%) rename {Odd or Even Game => Basic Math/Odd or Even Game}/.idea/misc.xml (100%) rename {Odd or Even Game => Basic Math/Odd or Even Game}/.idea/modules.xml (100%) rename {Odd or Even Game => Basic Math/Odd or Even Game}/.idea/vcs.xml (100%) rename {Odd or Even Game => Basic Math/Odd or Even Game}/.idea/workspace.xml (100%) rename {Odd or Even Game => Basic Math/Odd or Even Game}/OddEvenGame.txt (100%) rename {Odd or Even Game => Basic Math/Odd or Even Game}/oddEvenGame.py (100%) rename {PROXY => Basic Math/PROXY}/question.txt (100%) rename {PROXY => Basic Math/PROXY}/solution.cpp (100%) rename {Prime_gen => Basic Math/Prime_gen}/Prime Generator(prime_gen) (100%) rename {Prime_gen => Basic Math/Prime_gen}/prime_gen.cpp (100%) rename {Save the Prisoner! => Basic Math/Save the Prisoner!}/question.txt (100%) rename {Save the Prisoner! => Basic Math/Save the Prisoner!}/solution.cpp (100%) rename {Sherlock-and-the-beast => Basic Math/Sherlock-and-the-beast}/Sherlock-and-the-beast-problem.md (100%) rename {Sherlock-and-the-beast => Basic Math/Sherlock-and-the-beast}/solution.cpp (94%) rename {The Additionator => Basic Math/The Additionator}/The Additionator.txt (100%) rename {The Additionator => Basic Math/The Additionator}/solution.java (100%) rename {The Prime Game => Basic Math/The Prime Game}/Problem_statement.txt (99%) rename {The Prime Game => Basic Math/The Prime Game}/Solution.py (96%) rename {When to take medicine => Basic Math/When to take medicine}/problem_statement.txt (100%) rename {When to take medicine => Basic Math/When to take medicine}/when to take medicine_answer.txt (100%) rename {find_factorial_of_a_number => Basic Math/find_factorial_of_a_number}/find_factorial_of_a_number.txt (100%) rename {find_factorial_of_a_number => Basic Math/find_factorial_of_a_number}/solution.cpp (100%) rename {project_euler problem12 => Basic Math/project_euler problem12}/Highly divisible triangular number.cpp (100%) rename {project_euler problem12 => Basic Math/project_euler problem12}/problem (100%) rename {CollatzConjecture => Basic Program/CollatzConjecture}/CollatzConjecture.txt (100%) rename {CollatzConjecture => Basic Program/CollatzConjecture}/solution.c (95%) rename {EncoderProblem => Basic Program/EncoderProblem}/Encoder.java (100%) rename {EncoderProblem => Basic Program/EncoderProblem}/problem.txt (100%) rename {Leap Year => Basic Program/Leap Year}/instructions.txt (100%) rename {Leap Year => Basic Program/Leap Year}/ruby_solution.rb (100%) rename {Sleep_In => Basic Program/Sleep_In}/sleep_in.py (100%) rename {how-can-create-a-hackthoberfest-infinite-loop-in-python => Basic Program/how-can-create-a-hackthoberfest-infinite-loop-in-python}/hacktoberfest-loop.txt (100%) rename {how-can-create-a-hackthoberfest-infinite-loop-in-python => Basic Program/how-can-create-a-hackthoberfest-infinite-loop-in-python}/infinity-hscktoberfest-loop.py (100%) rename {Aggressive Cows Spoj => Binary Search/Aggressive Cows Spoj}/problem statement.txt (100%) rename {Aggressive Cows Spoj => Binary Search/Aggressive Cows Spoj}/solution1.cpp (100%) rename {Aggressive Cows Spoj => Binary Search/Aggressive Cows Spoj}/solution2.cpp (100%) rename {binary_search => Binary Search/binary_search}/binary_search.txt (100%) rename {binary_search => Binary Search/binary_search}/bs.class (100%) rename {binary_search => Binary Search/binary_search}/bs.ctxt (100%) rename {binary_search => Binary Search/binary_search}/bs.java (100%) rename {binary_search => Binary Search/binary_search}/solution.cpp (100%) rename {binary_search => Binary Search/binary_search}/solution.py (100%) rename {ZOMCAV => Bitwise Operation/ZOMCAV}/ZOMCAV.txt (100%) rename {ZOMCAV => Bitwise Operation/ZOMCAV}/codechef.class (100%) rename {ZOMCAV => Bitwise Operation/ZOMCAV}/codechef.ctxt (100%) rename {ZOMCAV => Bitwise Operation/ZOMCAV}/codechef.java (100%) rename {0-1 Knapsack Problem => Dynamic Programming/0-1 Knapsack Problem}/Question.txt (100%) rename {0-1 Knapsack Problem => Dynamic Programming/0-1 Knapsack Problem}/Solution.c (100%) rename {Buy-and-Sell-Stock-for-Maximum-Profit => Dynamic Programming/Buy-and-Sell-Stock-for-Maximum-Profit}/buyAndSellStock.py (100%) rename {Buy-and-Sell-Stock-for-Maximum-Profit => Dynamic Programming/Buy-and-Sell-Stock-for-Maximum-Profit}/problem-statement.txt (100%) rename {Bytelandian-gold-coins => Dynamic Programming/Bytelandian-gold-coins}/instructions.txt (100%) rename {Bytelandian-gold-coins => Dynamic Programming/Bytelandian-gold-coins}/solution.cpp (100%) rename {COINS => Dynamic Programming/COINS}/Question.txt (100%) rename {COINS => Dynamic Programming/COINS}/Readme.md (100%) rename {COINS => Dynamic Programming/COINS}/Solution.cpp (100%) rename {DP- Min Steps to 1 => Dynamic Programming/DP- Min Steps to 1}/Min Steps to 1 Problem Statement.txt (100%) rename {DP- Min Steps to 1 => Dynamic Programming/DP- Min Steps to 1}/minsteps.java (100%) rename {Magic-Spells-LCS => Dynamic Programming/Magic-Spells-LCS}/problem.txt (100%) rename {Magic-Spells-LCS => Dynamic Programming/Magic-Spells-LCS}/solution.cpp (100%) rename {Max_Sum_Contiguous_Subarray => Dynamic Programming/Max_Sum_Contiguous_Subarray}/Question.txt (100%) rename {Max_Sum_Contiguous_Subarray => Dynamic Programming/Max_Sum_Contiguous_Subarray}/Readme.md (100%) rename {Max_Sum_Contiguous_Subarray => Dynamic Programming/Max_Sum_Contiguous_Subarray}/Solution.cpp (100%) rename {Maximize the Product => Dynamic Programming/Maximize the Product}/Maximize the product.txt (100%) rename {Maximize the Product => Dynamic Programming/Maximize the Product}/solution.cpp (100%) rename {Maximum sum of digits => Dynamic Programming/Maximum sum of digits}/code.cpp (100%) rename {Maximum sum of digits => Dynamic Programming/Maximum sum of digits}/problem_statement.txt (100%) rename {Maximum-Perimeter-Triangle => Dynamic Programming/Maximum-Perimeter-Triangle}/Maximum-Perimeter-Triangle-Problem (100%) rename {Maximum-Perimeter-Triangle => Dynamic Programming/Maximum-Perimeter-Triangle}/Solution.cpp (100%) rename {Powerset => Dynamic Programming/Powerset}/powerset.js (100%) rename {Powerset => Dynamic Programming/Powerset}/question.txt (100%) rename {Prime_subsequence => Dynamic Programming/Prime_subsequence}/question.txt (100%) rename {Prime_subsequence => Dynamic Programming/Prime_subsequence}/solution.cpp (100%) rename {ROCK => Dynamic Programming/ROCK}/problem.txt (100%) rename {ROCK => Dynamic Programming/ROCK}/rock.cpp (100%) rename {Rod cutting problem => Dynamic Programming/Rod cutting problem}/question.txt (100%) rename {Rod cutting problem => Dynamic Programming/Rod cutting problem}/solution.java (100%) rename {The Mailbox Manufacturers Problem => Dynamic Programming/The Mailbox Manufacturers Problem}/mailbox-question.txt (100%) rename {The Mailbox Manufacturers Problem => Dynamic Programming/The Mailbox Manufacturers Problem}/solution.cpp (100%) rename {Zero_Sum_SubArray => Dynamic Programming/Zero_Sum_SubArray}/question.txt (100%) rename {Zero_Sum_SubArray => Dynamic Programming/Zero_Sum_SubArray}/solution.cpp (100%) rename {alphacode => Dynamic Programming/alphacode}/problem_statement.txt (100%) rename {alphacode => Dynamic Programming/alphacode}/solution.txt (100%) rename {Product_of_lengths_all_cycles_undirected_graph => Graph/Product_of_lengths_all_cycles_undirected_graph}/question.txt (100%) rename {Product_of_lengths_all_cycles_undirected_graph => Graph/Product_of_lengths_all_cycles_undirected_graph}/solution.cpp (100%) rename {The_Coin_Change_Problem => Greedy/The_Coin_Change_Problem}/Problem_Statement.txt (100%) rename {The_Coin_Change_Problem => Greedy/The_Coin_Change_Problem}/Solution.java (100%) rename {Implement a Line Editor with a Linked List => LinkedList/Implement a Line Editor with a Linked List}/Problem Statement.txt (100%) rename {Implement a Line Editor with a Linked List => LinkedList/Implement a Line Editor with a Linked List}/Solution.cpp (100%) rename {AAL => Patterns/AAL}/Aditya And Ladders.txt (100%) rename {AAL => Patterns/AAL}/x.cpp (100%) rename {PatternPrinting => Patterns/PatternPrinting}/README.md (100%) rename {PatternPrinting => Patterns/PatternPrinting}/sum.java (95%) rename {SpiralMatrix => Patterns/SpiralMatrix}/problem.txt (100%) rename {SpiralMatrix => Patterns/SpiralMatrix}/solution.cpp (100%) rename {Factorial using Recursion => Recursion/Factorial using Recursion}/Factorial using recursion.cpp (100%) rename {Factorial using Recursion => Recursion/Factorial using Recursion}/Question.txt (100%) rename {Tower-of-Hanoi => Recursion/Tower-of-Hanoi}/Hanoi.java (100%) rename {Tower-of-Hanoi => Recursion/Tower-of-Hanoi}/Tower of Hanoi.txt (100%) rename {In search of an easy problem => Searching/In search of an easy problem}/problem_statement.txt (100%) rename {In search of an easy problem => Searching/In search of an easy problem}/sol.cpp (100%) rename {SGU_weeds_344 => Searching/SGU_weeds_344}/weed.cpp (100%) rename {SGU_weeds_344 => Searching/SGU_weeds_344}/weed.txt (100%) rename {Get Longest Sorted Sequence => Sorting/Get Longest Sorted Sequence}/answer.py (100%) rename {Get Longest Sorted Sequence => Sorting/Get Longest Sorted Sequence}/problem.txt (100%) rename {Insertion_sort_using_classes => Sorting/Insertion_sort_using_classes}/insertion_sort.cpp (100%) rename {Insertion_sort_using_classes => Sorting/Insertion_sort_using_classes}/problem.txt (100%) rename {Mergesort-JS => Sorting/Mergesort-JS}/mergeSort.js (100%) rename {Mergesort-JS => Sorting/Mergesort-JS}/question.txt (100%) rename {Merging_Two_Sorted_Array => Sorting/Merging_Two_Sorted_Array}/question.txt (100%) rename {Merging_Two_Sorted_Array => Sorting/Merging_Two_Sorted_Array}/solution.cpp (100%) rename {Mersort_In_C++ => Sorting/Mersort_In_C++}/mergeSort.cpp (94%) mode change 100755 => 100644 rename {Mersort_In_C++ => Sorting/Mersort_In_C++}/mergesort.txt (100%) rename {Quicksort-JS => Sorting/Quicksort-JS}/question.txt (100%) rename {Quicksort-JS => Sorting/Quicksort-JS}/quickSort.js (100%) rename {Quicksort-python => Sorting/Quicksort-python}/Question.txt (100%) rename {Quicksort-python => Sorting/Quicksort-python}/algorithm.txt (100%) rename {Quicksort-python => Sorting/Quicksort-python}/quickSort.py (100%) mode change 100755 => 100644 rename {bubble_sort_c => Sorting/bubble_sort_c}/question.txt (100%) rename {bubble_sort_c => Sorting/bubble_sort_c}/solution/bubble_sort.c (100%) rename {bubble_sort_c => Sorting/bubble_sort_c}/solution/bubble_sort.h (100%) rename {bubble_sort_c => Sorting/bubble_sort_c}/solution/main.c (100%) rename {bubble_sort_c => Sorting/bubble_sort_c}/solution/print_array.c (100%) rename {Generate Parentheses => Stack/Generate Parentheses}/Question.txt (100%) rename {Generate Parentheses => Stack/Generate Parentheses}/Solution (100%) mode change 100755 => 100644 rename {Generate Parentheses => Stack/Generate Parentheses}/Solution.cpp (100%) rename {Street parade => Stack/Street parade}/code.cpp (100%) rename {Street parade => Stack/Street parade}/problem_statement.txt (100%) rename {AnagramChecking => String/AnagramChecking}/anagram_checking.py (100%) mode change 100755 => 100644 rename {AnagramChecking => String/AnagramChecking}/anagram_checking.txt (100%) rename {Arrangement_of_Queue => String/Arrangement_of_Queue}/Question.txt (100%) rename {Arrangement_of_Queue => String/Arrangement_of_Queue}/README.md (100%) rename {Arrangement_of_Queue => String/Arrangement_of_Queue}/Solution.py (100%) rename {Cenit-Polar-Crypt => String/Cenit-Polar-Crypt}/Issue.txt (100%) rename {Cenit-Polar-Crypt => String/Cenit-Polar-Crypt}/Solution.js (100%) rename {Check_String_Palindrome => String/Check_String_Palindrome}/Source1.cpp (100%) rename {Check_String_Palindrome => String/Check_String_Palindrome}/problem.txt (100%) rename {FANCY => String/FANCY}/problem.txt (100%) rename {FANCY => String/FANCY}/solution.py (100%) rename {Isograms => String/Isograms}/isograms.py (100%) rename {Isograms => String/Isograms}/problem_statement.txt (100%) rename {Palindrome => String/Palindrome}/palindrome.c (100%) rename {Palindrome => String/Palindrome}/question.txt (100%) rename {Python_Palindrome => String/Python_Palindrome}/PalindromeQues.txt (100%) rename {Python_Palindrome => String/Python_Palindrome}/solution.py (100%) rename {Reverse string in place => String/Reverse string in place}/question.txt (100%) rename {Reverse string in place => String/Reverse string in place}/solution.java (100%) rename {ReverseChars => String/ReverseChars}/ReverseChars.java (95%) rename {ReverseChars => String/ReverseChars}/problem.txt (100%) rename {SplitString => String/SplitString}/Question.txt (100%) rename {SplitString => String/SplitString}/Solution.cpp (100%) rename {String_Permutation => String/String_Permutation}/question.txt (100%) rename {String_Permutation => String/String_Permutation}/solution.cpp (100%) rename {StrongPassword => String/StrongPassword}/solution.py (100%) rename {StrongPassword => String/StrongPassword}/strongpasswordqn.txt (100%) rename {Subsequences => String/Subsequences}/question.txt (100%) rename {Subsequences => String/Subsequences}/subsequences.cpp (94%) mode change 100755 => 100644 rename {The Reversed World => String/The Reversed World}/Solution.cpp (100%) rename {The Reversed World => String/The Reversed World}/The Reversed World.txt (100%) rename {ToyObsession => String/ToyObsession}/problem.c (100%) rename {ToyObsession => String/ToyObsession}/solution.c (100%) rename {Word_Frequency => String/Word_Frequency}/question.txt (100%) rename {Word_Frequency => String/Word_Frequency}/solution.js (100%) rename {ginortS => String/ginortS}/Question.txt (100%) rename {ginortS => String/ginortS}/Solution.py (100%) rename {size-of-tree-C++ => Tree/size-of-tree-C++}/problem_statement.txt (100%) rename {size-of-tree-C++ => Tree/size-of-tree-C++}/sizeoftree.cpp (100%) rename {Acronym => Unknown/Acronym}/instructions.txt (100%) rename {Acronym => Unknown/Acronym}/ruby_solution.rb (100%) rename {CONTON => Unknown/CONTON}/QUESTION.txt (100%) rename {CONTON => Unknown/CONTON}/solution.c (100%) rename {Chefdil => Unknown/Chefdil}/ans.cpp (100%) rename {Chefdil => Unknown/Chefdil}/ques.txt (100%) rename {Chocolate_SPOJ => Unknown/Chocolate_SPOJ}/question.txt (100%) rename {Chocolate_SPOJ => Unknown/Chocolate_SPOJ}/solution.java (100%) rename {Fair Rations => Unknown/Fair Rations}/Answer.cpp (100%) rename {Fair Rations => Unknown/Fair Rations}/Problem Statement .txt (100%) rename {Industrial Nim => Unknown/Industrial Nim}/Industrial_Nim.cpp (100%) rename {Industrial Nim => Unknown/Industrial Nim}/Industrial_Nim.txt (100%) rename {Necklace => Unknown/Necklace}/solution.cpp (100%) rename {Necklace => Unknown/Necklace}/statement.pdf (100%) rename {PINS => Unknown/PINS}/problem.txt (100%) rename {PINS => Unknown/PINS}/solution.cpp (100%) rename {PolyMul => Unknown/PolyMul}/question.txt (100%) rename {PolyMul => Unknown/PolyMul}/solution.cpp (100%) rename {Strange_Food_Chain => Unknown/Strange_Food_Chain}/question.txt (100%) rename {Strange_Food_Chain => Unknown/Strange_Food_Chain}/solution.cpp (100%) rename {WATCHFB => Unknown/WATCHFB}/Main.class (100%) rename {WATCHFB => Unknown/WATCHFB}/Main.ctxt (100%) rename {WATCHFB => Unknown/WATCHFB}/Main.java (100%) rename {WATCHFB => Unknown/WATCHFB}/WATCHFB.txt (100%) rename {chusky_adventurer => Unknown/chusky_adventurer}/problem_statement.txt (100%) rename {chusky_adventurer => Unknown/chusky_adventurer}/solution.cpp (100%) rename {chusky_hunger => Unknown/chusky_hunger}/problem_statement.txt (100%) rename {chusky_hunger => Unknown/chusky_hunger}/solution.cpp (100%) rename {chusky_nightgame => Unknown/chusky_nightgame}/problem_statement.txt (100%) rename {chusky_nightgame => Unknown/chusky_nightgame}/solution.cpp (100%) rename {coin-piles => Unknown/coin-piles}/problem_statement.txt (100%) rename {coin-piles => Unknown/coin-piles}/solution.cpp (100%) diff --git a/FCFS/fcfs.py b/Algorithm/FCFS/fcfs.py similarity index 100% rename from FCFS/fcfs.py rename to Algorithm/FCFS/fcfs.py diff --git a/FCFS/question.txt b/Algorithm/FCFS/question.txt similarity index 100% rename from FCFS/question.txt rename to Algorithm/FCFS/question.txt diff --git a/Floodfill/Problem_statement.txt b/Algorithm/Floodfill/Problem_statement.txt similarity index 97% rename from Floodfill/Problem_statement.txt rename to Algorithm/Floodfill/Problem_statement.txt index 9ddda57..f36d41a 100644 --- a/Floodfill/Problem_statement.txt +++ b/Algorithm/Floodfill/Problem_statement.txt @@ -1,28 +1,28 @@ -For those who don’t like regular images, ASCII Maps Inc. has created maps that are fully printable ASCII characters. Each map is a rectangular grid of lowercase English letters, where each letter stands for various locations. In particular, ‘w’ stands for water and the other 25 letters represent various different land locations. For this problem, we are interested in counting the number of bodies of water on a given ASCII map. A body of water is a maximal set of contiguous grid squares on the ASCII map where each square in the body of water shares a boundary with at least one other square in the body of water. Thus, for two grid squares to be part of the same body of water, one must be above, below, to the left, or to the right of the other grid square. -Input -The first line of input consists of two space separated integers, r (1=r=50) and c (1=c=50), the number of rows and columns, respectively for the input map. The next r lines will each contain c lowercase English letters, representing the corresponding row of the input map. - -Output -On a line by itself, output the number of bodies of water in the input map. - -Sample test case 1: - -Input: -5 6 -waaaww -wawawc -bbbbwc -wwwwww -dddddd - -Output: -3 - -Sample test case 2: -Input: -2 8 -wxwxwxwx -xwxwxwxw - -Output: -8 +For those who don’t like regular images, ASCII Maps Inc. has created maps that are fully printable ASCII characters. Each map is a rectangular grid of lowercase English letters, where each letter stands for various locations. In particular, ‘w’ stands for water and the other 25 letters represent various different land locations. For this problem, we are interested in counting the number of bodies of water on a given ASCII map. A body of water is a maximal set of contiguous grid squares on the ASCII map where each square in the body of water shares a boundary with at least one other square in the body of water. Thus, for two grid squares to be part of the same body of water, one must be above, below, to the left, or to the right of the other grid square. +Input +The first line of input consists of two space separated integers, r (1=r=50) and c (1=c=50), the number of rows and columns, respectively for the input map. The next r lines will each contain c lowercase English letters, representing the corresponding row of the input map. + +Output +On a line by itself, output the number of bodies of water in the input map. + +Sample test case 1: + +Input: +5 6 +waaaww +wawawc +bbbbwc +wwwwww +dddddd + +Output: +3 + +Sample test case 2: +Input: +2 8 +wxwxwxwx +xwxwxwxw + +Output: +8 diff --git a/Floodfill/solution.java b/Algorithm/Floodfill/solution.java similarity index 95% rename from Floodfill/solution.java rename to Algorithm/Floodfill/solution.java index 2974a5a..a043c94 100644 --- a/Floodfill/solution.java +++ b/Algorithm/Floodfill/solution.java @@ -1,53 +1,53 @@ -import java.util.Arrays; -import java.util.Scanner; - -public class water { -public static void main(String[] args){ -Scanner kb=new Scanner(System.in); -System.out.println("Enter the dimensions of the map:"); -int n=kb.nextInt(); -int m=kb.nextInt(); -System.out.println("Enter the map:"); -char[][] x=new char[n][m]; -for(int i=0;i=0&&r=0&&c=0&&r=0&&c -#include - -int maxSubarraySum(int a[], int l) { - int max = INT_MIN, max_here = 0; - - for (int i = 0; i < l; i++) { - max_here = max_here + a[i]; - if (max < max_here) max = max_here; - if (max_here < 0) max_here = 0; - } - - return max; -} - -// int maxSubarraySum(int a[], int l) { -// int max = a[0], max_here = a[0]; - -// for (int i = 0; i < l; i++) { -// if (max_here > 0) max_here += a[i]; -// else max_here = a[i]; -// if (max_here > max) max = max_here; -// } - -// return max; -// } - -int main(int argc, char *argv[]) { - int arr[] = {-2, -3, 4, -1, -2, 1, 5, -3}; - int l = sizeof(arr) / sizeof(int); - - int m = maxSubarraySum(arr, l); - - printf("%d is the max subarray sum\n", m); - - return 0; +#include +#include + +int maxSubarraySum(int a[], int l) { + int max = INT_MIN, max_here = 0; + + for (int i = 0; i < l; i++) { + max_here = max_here + a[i]; + if (max < max_here) max = max_here; + if (max_here < 0) max_here = 0; + } + + return max; +} + +// int maxSubarraySum(int a[], int l) { +// int max = a[0], max_here = a[0]; + +// for (int i = 0; i < l; i++) { +// if (max_here > 0) max_here += a[i]; +// else max_here = a[i]; +// if (max_here > max) max = max_here; +// } + +// return max; +// } + +int main(int argc, char *argv[]) { + int arr[] = {-2, -3, 4, -1, -2, 1, 5, -3}; + int l = sizeof(arr) / sizeof(int); + + int m = maxSubarraySum(arr, l); + + printf("%d is the max subarray sum\n", m); + + return 0; } \ No newline at end of file diff --git a/Kadane's Algorithm/kadane.cpp b/Algorithm/Kadane's Algorithm/kadane.cpp similarity index 100% rename from Kadane's Algorithm/kadane.cpp rename to Algorithm/Kadane's Algorithm/kadane.cpp diff --git a/Kadane's Algorithm/kadane.py b/Algorithm/Kadane's Algorithm/kadane.py similarity index 100% rename from Kadane's Algorithm/kadane.py rename to Algorithm/Kadane's Algorithm/kadane.py diff --git a/Kadane's Algorithm/problem.txt b/Algorithm/Kadane's Algorithm/problem.txt similarity index 96% rename from Kadane's Algorithm/problem.txt rename to Algorithm/Kadane's Algorithm/problem.txt index ad9467e..1f05316 100644 --- a/Kadane's Algorithm/problem.txt +++ b/Algorithm/Kadane's Algorithm/problem.txt @@ -1,5 +1,5 @@ -Problem: -Find out the maximum continuous subarray sum in linear time - -Solution: -Kadane's algorithm can calculate the maximum subarray sum in linear time +Problem: +Find out the maximum continuous subarray sum in linear time + +Solution: +Kadane's algorithm can calculate the maximum subarray sum in linear time diff --git a/hot_potato/hot_potato.cpp b/Algorithm/hot_potato/hot_potato.cpp similarity index 100% rename from hot_potato/hot_potato.cpp rename to Algorithm/hot_potato/hot_potato.cpp diff --git a/hot_potato/question.txt b/Algorithm/hot_potato/question.txt similarity index 100% rename from hot_potato/question.txt rename to Algorithm/hot_potato/question.txt diff --git a/nQueen/Question.txt b/Algorithm/nQueen/Question.txt similarity index 100% rename from nQueen/Question.txt rename to Algorithm/nQueen/Question.txt diff --git a/nQueen/nQueen.cpp b/Algorithm/nQueen/nQueen.cpp old mode 100755 new mode 100644 similarity index 96% rename from nQueen/nQueen.cpp rename to Algorithm/nQueen/nQueen.cpp index 0cfd39c..505b926 --- a/nQueen/nQueen.cpp +++ b/Algorithm/nQueen/nQueen.cpp @@ -1,90 +1,90 @@ - -#include -using namespace std; - -char board[30][30]; - -void printBoard(char arr[][30], int n) { - for (int r = 0; r < n; ++r) { - for (int c = 0; c < n; ++c) { - cout << arr[r][c] << " " ; - } - cout << endl; - } -} - -void initialiseBoard(int n) { - for (int r = 0; r < n; ++r) { - for (int c = 0; c < n; ++c) { - board[r][c] = 'X'; - } - } -} - -bool canPlace(char board[][30], int N, int x, int y) -{ - //check the row if aqueen already exists - for (int r = 0; r < N; ++r) - { - if (board[r][y] == 'Q') - return false; - } - - int rInc[] = { -1, +1, +1, -1}; - int cInc[] = { -1, +1, -1, +1}; - //check diagonal if queen already exists - for (int dir = 0; dir < 4; ++dir) - { - int rowAdd = rInc[dir]; - int colAdd = cInc[dir]; - int r = x + rowAdd; - int c = y + colAdd; - //check that r c is within the board - while (r >= 0 && r < N && c >= 0 && c < N) - { - if (board[r][c] == 'Q') - return false; - r = r + rowAdd; - c = c + colAdd; - } - } - return true; -} - -bool nqueen(int r, int n) -{ - if (r == n)//base case if all queens are placed - { - return true; - } - //for every column, use hit and trial by placing a queen in the each cell of curr Row - for (int c = 0; c < n; ++c) - { - int x = r; - int y = c; - //check if queen can be placed on board[i][c] - if (canPlace(board, n, x, y)==true) - { - board[x][y] = 'Q'; //place queen in each column - bool isSuccessful = nqueen(r + 1, n); //recursion to place rest of queens - if (isSuccessful == true) - return true; - board[x][y] = 'X'; //else unmark the cell or backtrack - } - } - return false; //if queen cannot be placed in any row in this column then return false -} - -int main() -{ - int n; - cin >> n; - - initialiseBoard(n);//initialse all the board with X - bool isSuccessful = nqueen(0, n); - - if (isSuccessful) printBoard(board, n); - else cout << "Sorry man! You need to have a larger board!\n"; - - return 0; -} + +#include +using namespace std; + +char board[30][30]; + +void printBoard(char arr[][30], int n) { + for (int r = 0; r < n; ++r) { + for (int c = 0; c < n; ++c) { + cout << arr[r][c] << " " ; + } + cout << endl; + } +} + +void initialiseBoard(int n) { + for (int r = 0; r < n; ++r) { + for (int c = 0; c < n; ++c) { + board[r][c] = 'X'; + } + } +} + +bool canPlace(char board[][30], int N, int x, int y) +{ + //check the row if aqueen already exists + for (int r = 0; r < N; ++r) + { + if (board[r][y] == 'Q') + return false; + } + + int rInc[] = { -1, +1, +1, -1}; + int cInc[] = { -1, +1, -1, +1}; + //check diagonal if queen already exists + for (int dir = 0; dir < 4; ++dir) + { + int rowAdd = rInc[dir]; + int colAdd = cInc[dir]; + int r = x + rowAdd; + int c = y + colAdd; + //check that r c is within the board + while (r >= 0 && r < N && c >= 0 && c < N) + { + if (board[r][c] == 'Q') + return false; + r = r + rowAdd; + c = c + colAdd; + } + } + return true; +} + +bool nqueen(int r, int n) +{ + if (r == n)//base case if all queens are placed + { + return true; + } + //for every column, use hit and trial by placing a queen in the each cell of curr Row + for (int c = 0; c < n; ++c) + { + int x = r; + int y = c; + //check if queen can be placed on board[i][c] + if (canPlace(board, n, x, y)==true) + { + board[x][y] = 'Q'; //place queen in each column + bool isSuccessful = nqueen(r + 1, n); //recursion to place rest of queens + if (isSuccessful == true) + return true; + board[x][y] = 'X'; //else unmark the cell or backtrack + } + } + return false; //if queen cannot be placed in any row in this column then return false +} + +int main() +{ + int n; + cin >> n; + + initialiseBoard(n);//initialse all the board with X + bool isSuccessful = nqueen(0, n); + + if (isSuccessful) printBoard(board, n); + else cout << "Sorry man! You need to have a larger board!\n"; + + return 0; +} diff --git a/Biggest_Sum_5_Consecutives_Integers/Biggest_Sum_5_Consecutives_Integers b/Array/Biggest_Sum_5_Consecutives_Integers/Biggest_Sum_5_Consecutives_Integers similarity index 100% rename from Biggest_Sum_5_Consecutives_Integers/Biggest_Sum_5_Consecutives_Integers rename to Array/Biggest_Sum_5_Consecutives_Integers/Biggest_Sum_5_Consecutives_Integers diff --git a/Biggest_Sum_5_Consecutives_Integers/solution.c b/Array/Biggest_Sum_5_Consecutives_Integers/solution.c similarity index 97% rename from Biggest_Sum_5_Consecutives_Integers/solution.c rename to Array/Biggest_Sum_5_Consecutives_Integers/solution.c index 086bd3f..4a395d4 100644 --- a/Biggest_Sum_5_Consecutives_Integers/solution.c +++ b/Array/Biggest_Sum_5_Consecutives_Integers/solution.c @@ -1,23 +1,23 @@ -#include -#include - -int main(){ - int i; - int size = 81; //SIZE OF THE ARRAY - int sum; - int biggestSum; - int array[] = {1, 3, -5, 8, -9, 13, -2, -3, 8, 4, 3, 6, 1, 2, -2, -4, 8, -4, 1, 8, 2, 1, 3, 1, 2, 3, 7, 8, -9, 5, 4, 3, 2, 4, 1, 2, 6, 6, 7, -15, 9, 7, 8, 16, -10, 1, 2, 6, 6, 4, -5, 2, 2, 3, 6, 7, 8, 1, 2, 3, 3, 4, 5, 6, 1, -5, 7, -9, 10, 1, 3, 4, 8, 7, 6, 4, 1, 1, 2, 3, 1}; - - //FIRST SUM - sum = array[0] + array[1] + array[2] + array[3] + array[4]; - biggestSum = sum; - - //OTHER SUMS - for(i = 1; i < (size - 4); i++){ //THERE ARE (size - 4) POSSIBLE SUMS, BUT WE ALREADY MADE 1, SO i STARTS AT 1 - sum = sum - array[i - 1] + array[i + 4]; //REMOVE THE FIRST OF THE OLD SUM, AND ADD THE NEW INTEGER - if(sum > biggestSum){ - biggestSum = sum; - } - } - printf("biggestSum = %d\n", biggestSum); //PRINT THE RESULT +#include +#include + +int main(){ + int i; + int size = 81; //SIZE OF THE ARRAY + int sum; + int biggestSum; + int array[] = {1, 3, -5, 8, -9, 13, -2, -3, 8, 4, 3, 6, 1, 2, -2, -4, 8, -4, 1, 8, 2, 1, 3, 1, 2, 3, 7, 8, -9, 5, 4, 3, 2, 4, 1, 2, 6, 6, 7, -15, 9, 7, 8, 16, -10, 1, 2, 6, 6, 4, -5, 2, 2, 3, 6, 7, 8, 1, 2, 3, 3, 4, 5, 6, 1, -5, 7, -9, 10, 1, 3, 4, 8, 7, 6, 4, 1, 1, 2, 3, 1}; + + //FIRST SUM + sum = array[0] + array[1] + array[2] + array[3] + array[4]; + biggestSum = sum; + + //OTHER SUMS + for(i = 1; i < (size - 4); i++){ //THERE ARE (size - 4) POSSIBLE SUMS, BUT WE ALREADY MADE 1, SO i STARTS AT 1 + sum = sum - array[i - 1] + array[i + 4]; //REMOVE THE FIRST OF THE OLD SUM, AND ADD THE NEW INTEGER + if(sum > biggestSum){ + biggestSum = sum; + } + } + printf("biggestSum = %d\n", biggestSum); //PRINT THE RESULT } \ No newline at end of file diff --git a/Circle Coloring/1408A.cpp b/Array/Circle Coloring/1408A.cpp similarity index 100% rename from Circle Coloring/1408A.cpp rename to Array/Circle Coloring/1408A.cpp diff --git a/Circle Coloring/question 1408A.txt b/Array/Circle Coloring/question 1408A.txt similarity index 100% rename from Circle Coloring/question 1408A.txt rename to Array/Circle Coloring/question 1408A.txt diff --git a/Lily's Homework/Question.txt b/Array/Lily's Homework/Question.txt similarity index 98% rename from Lily's Homework/Question.txt rename to Array/Lily's Homework/Question.txt index 502c95c..39f207f 100644 --- a/Lily's Homework/Question.txt +++ b/Array/Lily's Homework/Question.txt @@ -1,11 +1,11 @@ -Consider an array of distinct integers, arr = [a[0], a[1], ..., a[n-1]]. George can swap any two elements of the array any number of times. An array is beautiful if the sum of |arr[i] - arr[i-1]|among 0< i < n is minimal. - -Given the array , determine and return the minimum number of swaps that should be performed in order to make the array beautiful. - -For example, arr = [7, 15, 12, 3]. One minimal array is [3, 7, 12, 15]. To get there, George performed the following swaps: - -Swap Result - [7, 15, 12, 3] -3 7 [3, 15, 12, 7] -7 15 [3, 7, 12, 15] +Consider an array of distinct integers, arr = [a[0], a[1], ..., a[n-1]]. George can swap any two elements of the array any number of times. An array is beautiful if the sum of |arr[i] - arr[i-1]|among 0< i < n is minimal. + +Given the array , determine and return the minimum number of swaps that should be performed in order to make the array beautiful. + +For example, arr = [7, 15, 12, 3]. One minimal array is [3, 7, 12, 15]. To get there, George performed the following swaps: + +Swap Result + [7, 15, 12, 3] +3 7 [3, 15, 12, 7] +7 15 [3, 7, 12, 15] It took 2 swaps to make the array beautiful. This is minimal among the choice of beautiful arrays possible. \ No newline at end of file diff --git a/Lily's Homework/solution.py b/Array/Lily's Homework/solution.py similarity index 96% rename from Lily's Homework/solution.py rename to Array/Lily's Homework/solution.py index 8b29419..7783d49 100644 --- a/Lily's Homework/solution.py +++ b/Array/Lily's Homework/solution.py @@ -1,26 +1,26 @@ -def lilysHomework(arr): - m = {} - for i in range(len(arr)): - m[arr[i]] = i - sorted_arr = sorted(arr) - res = 0 - for i in range(len(arr)): - if(arr[i] != sorted_arr[i]): - res += 1 - x = m[sorted_arr[i]] - m[ arr[i] ] = m[ sorted_arr[i]] - arr[i],arr[x] = sorted_arr[i],arr[i] - return res - -if __name__ == '__main__': - fptr = open(os.environ['OUTPUT_PATH'], 'w') - - n = int(input()) - - arr = list(map(int, input().rstrip().split())) - - result = min(lilysHomework(list(arr)), lilysHomework(list(arr[::-1]))) - - fptr.write(str(result) + '\n') - - fptr.close() +def lilysHomework(arr): + m = {} + for i in range(len(arr)): + m[arr[i]] = i + sorted_arr = sorted(arr) + res = 0 + for i in range(len(arr)): + if(arr[i] != sorted_arr[i]): + res += 1 + x = m[sorted_arr[i]] + m[ arr[i] ] = m[ sorted_arr[i]] + arr[i],arr[x] = sorted_arr[i],arr[i] + return res + +if __name__ == '__main__': + fptr = open(os.environ['OUTPUT_PATH'], 'w') + + n = int(input()) + + arr = list(map(int, input().rstrip().split())) + + result = min(lilysHomework(list(arr)), lilysHomework(list(arr[::-1]))) + + fptr.write(str(result) + '\n') + + fptr.close() diff --git a/Mislove Has Lost an Array/Question.txt b/Array/Mislove Has Lost an Array/Question.txt similarity index 100% rename from Mislove Has Lost an Array/Question.txt rename to Array/Mislove Has Lost an Array/Question.txt diff --git a/Mislove Has Lost an Array/Solution.cpp b/Array/Mislove Has Lost an Array/Solution.cpp similarity index 100% rename from Mislove Has Lost an Array/Solution.cpp rename to Array/Mislove Has Lost an Array/Solution.cpp diff --git a/Omar and Candies/Problem Statement.txt b/Array/Omar and Candies/Problem Statement.txt similarity index 100% rename from Omar and Candies/Problem Statement.txt rename to Array/Omar and Candies/Problem Statement.txt diff --git a/Omar and Candies/Solution.c b/Array/Omar and Candies/Solution.c similarity index 100% rename from Omar and Candies/Solution.c rename to Array/Omar and Candies/Solution.c diff --git a/Philosophers_Stone/question.txt b/Array/Philosophers_Stone/question.txt similarity index 100% rename from Philosophers_Stone/question.txt rename to Array/Philosophers_Stone/question.txt diff --git a/Philosophers_Stone/solution.cpp b/Array/Philosophers_Stone/solution.cpp similarity index 100% rename from Philosophers_Stone/solution.cpp rename to Array/Philosophers_Stone/solution.cpp diff --git a/Phone price/solution.cpp b/Array/Phone price/solution.cpp similarity index 100% rename from Phone price/solution.cpp rename to Array/Phone price/solution.cpp diff --git a/Phone price/statement.txt b/Array/Phone price/statement.txt similarity index 100% rename from Phone price/statement.txt rename to Array/Phone price/statement.txt diff --git a/Sieve of Eratosthenes/Question.txt b/Array/Sieve of Eratosthenes/Question.txt similarity index 100% rename from Sieve of Eratosthenes/Question.txt rename to Array/Sieve of Eratosthenes/Question.txt diff --git a/Sieve of Eratosthenes/Solution.cpp b/Array/Sieve of Eratosthenes/Solution.cpp similarity index 100% rename from Sieve of Eratosthenes/Solution.cpp rename to Array/Sieve of Eratosthenes/Solution.cpp diff --git a/TRUEDARE/QUESTION.txt b/Array/TRUEDARE/QUESTION.txt similarity index 100% rename from TRUEDARE/QUESTION.txt rename to Array/TRUEDARE/QUESTION.txt diff --git a/TRUEDARE/SOLUTION.txt b/Array/TRUEDARE/SOLUTION.txt similarity index 100% rename from TRUEDARE/SOLUTION.txt rename to Array/TRUEDARE/SOLUTION.txt diff --git a/White-Sheet/White-Sheet.txt b/Array/White-Sheet/White-Sheet.txt similarity index 97% rename from White-Sheet/White-Sheet.txt rename to Array/White-Sheet/White-Sheet.txt index e865c86..57d317d 100644 --- a/White-Sheet/White-Sheet.txt +++ b/Array/White-Sheet/White-Sheet.txt @@ -1,54 +1,54 @@ -There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle with its sides parallel to the sides of the table. If you will take a look from above and assume that the bottom left corner of the table has coordinates (0,0), and coordinate axes are left and bottom sides of the table, then the bottom left corner of the white sheet has coordinates (x1,y1), and the top right — (x2,y2). -After that two black sheets of paper are placed on the table. Sides of both black sheets are also parallel to the sides of the table. Coordinates of the bottom left corner of the first black sheet are (x3,y3), and the top right — (x4,y4). Coordinates of the bottom left corner of the second black sheet are (x5,y5), and the top right — (x6,y6). - - -Determine if some part of the white sheet can be seen from the above after the two black sheets are placed. The part of the white sheet can be seen if there is at least one point lying not strictly inside the white sheet and strictly outside of both black sheets. -Input -The first line of the input contains four integers x1,y1,x2,y2 (0≤x1 -#include -using namespace std; - -void print2D(int arr[][20], int M, int N) { - for (int i = 0; i < M; ++i) { - for (int j = 0; j < N; ++j) { - cout << arr[i][j] << " "; - } - cout << endl; - } -} - -bool myfixed[20][20] = {}; - -void input2D_soduku(int arr[][20], int M, int N) -{ - for (int i = 0; i < M; ++i) - { - for (int j = 0; j < N; ++j) - { - cin >> arr[i][j]; - if (arr[i][j] != 0) myfixed[i][j] = true; //so that our entry does not change - } - } -} - -bool canPlace(int board[][20], int N, int x, int y, int num) -{ - //check along row && col - for (int i = 0; i < N; ++i) - { - if (board[x][i] == num) return false; //check along row - if (board[i][y] == num) return false; //check along col - } - - //check in the box - int rootN = sqrt(N); - int boxRow = x / rootN; - int boxCol = y / rootN; - int startRow = boxRow * rootN; - int startCol = boxCol * rootN; - - for (int r = startRow; r < startRow + rootN; ++r) - { - for (int c = startCol; c < startCol + rootN; ++c) - { - if (board[r][c] == num) return false; - } - } - - return true; -} - - -bool solveSudoku(int board[][20], int N, int x, int y) -{ - if (x == N && y == 0) return true; //we have reached row 4 ---->sudoku over - - if (y == N) return solveSudoku(board, N, x + 1, 0);//stop y to go to column4-->goto nxt row - - if (myfixed[x][y]) return solveSudoku(board, N, x , y + 1); - - for (int num = 1; num <= N; ++num) - { - if (canPlace(board, N, x, y, num) == true) - { - board[x][y] = num; - bool isSuccessful = solveSudoku(board, N, x , y + 1); //recursion for nxt columns - if (isSuccessful) return true; - else board[x][y] = 0; - } - } - return false; -} - -int main() -{ - int board[20][20] = {}; - - int N; - cin >> N; - input2D_soduku(board, N, N); - for(int i=0;i>board[i][j]; - } - } - cout << "==============\n"; - - print2D(board, N, N); - - cout << "==============\n"; - - solveSudoku(board, N, 0, 0); - - print2D(board, N, N); - -} - +#include +#include +using namespace std; + +void print2D(int arr[][20], int M, int N) { + for (int i = 0; i < M; ++i) { + for (int j = 0; j < N; ++j) { + cout << arr[i][j] << " "; + } + cout << endl; + } +} + +bool myfixed[20][20] = {}; + +void input2D_soduku(int arr[][20], int M, int N) +{ + for (int i = 0; i < M; ++i) + { + for (int j = 0; j < N; ++j) + { + cin >> arr[i][j]; + if (arr[i][j] != 0) myfixed[i][j] = true; //so that our entry does not change + } + } +} + +bool canPlace(int board[][20], int N, int x, int y, int num) +{ + //check along row && col + for (int i = 0; i < N; ++i) + { + if (board[x][i] == num) return false; //check along row + if (board[i][y] == num) return false; //check along col + } + + //check in the box + int rootN = sqrt(N); + int boxRow = x / rootN; + int boxCol = y / rootN; + int startRow = boxRow * rootN; + int startCol = boxCol * rootN; + + for (int r = startRow; r < startRow + rootN; ++r) + { + for (int c = startCol; c < startCol + rootN; ++c) + { + if (board[r][c] == num) return false; + } + } + + return true; +} + + +bool solveSudoku(int board[][20], int N, int x, int y) +{ + if (x == N && y == 0) return true; //we have reached row 4 ---->sudoku over + + if (y == N) return solveSudoku(board, N, x + 1, 0);//stop y to go to column4-->goto nxt row + + if (myfixed[x][y]) return solveSudoku(board, N, x , y + 1); + + for (int num = 1; num <= N; ++num) + { + if (canPlace(board, N, x, y, num) == true) + { + board[x][y] = num; + bool isSuccessful = solveSudoku(board, N, x , y + 1); //recursion for nxt columns + if (isSuccessful) return true; + else board[x][y] = 0; + } + } + return false; +} + +int main() +{ + int board[20][20] = {}; + + int N; + cin >> N; + input2D_soduku(board, N, N); + for(int i=0;i>board[i][j]; + } + } + cout << "==============\n"; + + print2D(board, N, N); + + cout << "==============\n"; + + solveSudoku(board, N, 0, 0); + + print2D(board, N, N); + +} + diff --git a/Armstrong No/armstrongnum.c b/Basic Math/Armstrong No/armstrongnum.c similarity index 100% rename from Armstrong No/armstrongnum.c rename to Basic Math/Armstrong No/armstrongnum.c diff --git a/Average/Average-Question.txt b/Basic Math/Average/Average-Question.txt similarity index 100% rename from Average/Average-Question.txt rename to Basic Math/Average/Average-Question.txt diff --git a/Average/Solution.cpp b/Basic Math/Average/Solution.cpp similarity index 100% rename from Average/Solution.cpp rename to Basic Math/Average/Solution.cpp diff --git a/Counting-Change-Combinations/counting.txt b/Basic Math/Counting-Change-Combinations/counting.txt similarity index 100% rename from Counting-Change-Combinations/counting.txt rename to Basic Math/Counting-Change-Combinations/counting.txt diff --git a/Counting-Change-Combinations/solution.js b/Basic Math/Counting-Change-Combinations/solution.js similarity index 100% rename from Counting-Change-Combinations/solution.js rename to Basic Math/Counting-Change-Combinations/solution.js diff --git a/Divisibility_Check/Question.txt b/Basic Math/Divisibility_Check/Question.txt similarity index 100% rename from Divisibility_Check/Question.txt rename to Basic Math/Divisibility_Check/Question.txt diff --git a/Divisibility_Check/Solution.cpp b/Basic Math/Divisibility_Check/Solution.cpp similarity index 100% rename from Divisibility_Check/Solution.cpp rename to Basic Math/Divisibility_Check/Solution.cpp diff --git a/Divisible Sum Pairs/Problem Description.txt b/Basic Math/Divisible Sum Pairs/Problem Description.txt similarity index 98% rename from Divisible Sum Pairs/Problem Description.txt rename to Basic Math/Divisible Sum Pairs/Problem Description.txt index 7525f0e..1ffa981 100644 --- a/Divisible Sum Pairs/Problem Description.txt +++ b/Basic Math/Divisible Sum Pairs/Problem Description.txt @@ -1,2 +1,2 @@ -You are given an array of n integers, ar = [ar[0], ar[1], ... , ar[n-1]], and a positive integer k. Find and print the number of -(i,j) pairs where i < j and ar[i]+ar[j] is divisible by k. +You are given an array of n integers, ar = [ar[0], ar[1], ... , ar[n-1]], and a positive integer k. Find and print the number of +(i,j) pairs where i < j and ar[i]+ar[j] is divisible by k. diff --git a/Divisible Sum Pairs/solution.js b/Basic Math/Divisible Sum Pairs/solution.js similarity index 95% rename from Divisible Sum Pairs/solution.js rename to Basic Math/Divisible Sum Pairs/solution.js index d75bca6..7c65521 100644 --- a/Divisible Sum Pairs/solution.js +++ b/Basic Math/Divisible Sum Pairs/solution.js @@ -1,12 +1,12 @@ -function divisibleSumPairs(n, k, ar) { - let count =0; - for(let i=0; i -void main() -{ - int i; - for(i=1;i<=100;i++) - { - if(i%3!=0 && i%5!=0) printf("%d\n", i); - if(i%3 == 0 && i%5!=0)printf("Fizz\n"); - if(i%5 == 0 && i%3!=0)printf("Buzz\n"); - if(i%5 == 0 && i%3==0)printf("FizzBuzz\n"); - } -} +#include +void main() +{ + int i; + for(i=1;i<=100;i++) + { + if(i%3!=0 && i%5!=0) printf("%d\n", i); + if(i%3 == 0 && i%5!=0)printf("Fizz\n"); + if(i%5 == 0 && i%3!=0)printf("Buzz\n"); + if(i%5 == 0 && i%3==0)printf("FizzBuzz\n"); + } +} diff --git a/Fizz Buzz/fizzbuzz.cpp b/Basic Math/Fizz Buzz/fizzbuzz.cpp similarity index 95% rename from Fizz Buzz/fizzbuzz.cpp rename to Basic Math/Fizz Buzz/fizzbuzz.cpp index 22eea15..4d6c904 100644 --- a/Fizz Buzz/fizzbuzz.cpp +++ b/Basic Math/Fizz Buzz/fizzbuzz.cpp @@ -1,16 +1,16 @@ -#include -using namespace std; -int main() -{ - for(int i=1;i<=100;i++){ - if((i%3 == 0) && (i%5==0)) - cout<<"FizzBuzz\n"; - else if(i%3 == 0) - cout<<"Fizz\n"; - else if(i%5 == 0) - cout<<"Buzz\n"; - else - cout< +using namespace std; +int main() +{ + for(int i=1;i<=100;i++){ + if((i%3 == 0) && (i%5==0)) + cout<<"FizzBuzz\n"; + else if(i%3 == 0) + cout<<"Fizz\n"; + else if(i%5 == 0) + cout<<"Buzz\n"; + else + cout< 0; i--) { - caracter = tmp.substring(i-1, i); - multiple = (int) Math.pow(BASE_8, count); - int value = (Integer.parseInt(caracter) * multiple); - count = count + 1; - result += value; - - } - - return String.valueOf(result); - } - -} +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class OctalDecimalCalculator { + + private static int BASE_8 = 8; + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final String RESULT_TEMPLATE = "The decimal number for octal %s is: %s"; + + public static void main(String[] args){ + + System.out.println("Please input octal number to convert"); + try { + String octal = br.readLine(); + String decimal = convertOctalToDecimal(Integer.parseInt(octal)); + + System.out.println(String.format(RESULT_TEMPLATE, octal, decimal)); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + public static String convertOctalToDecimal(int octal){ + int result = 0; + String tmp = String.valueOf(octal); + int count = 0; + int multiple; + String caracter; + for (int i = tmp.length(); i > 0; i--) { + caracter = tmp.substring(i-1, i); + multiple = (int) Math.pow(BASE_8, count); + int value = (Integer.parseInt(caracter) * multiple); + count = count + 1; + result += value; + + } + + return String.valueOf(result); + } + +} diff --git a/Odd or Even Game/.idea/Odd or Even Game.iml b/Basic Math/Odd or Even Game/.idea/Odd or Even Game.iml similarity index 100% rename from Odd or Even Game/.idea/Odd or Even Game.iml rename to Basic Math/Odd or Even Game/.idea/Odd or Even Game.iml diff --git a/Odd or Even Game/.idea/misc.xml b/Basic Math/Odd or Even Game/.idea/misc.xml similarity index 100% rename from Odd or Even Game/.idea/misc.xml rename to Basic Math/Odd or Even Game/.idea/misc.xml diff --git a/Odd or Even Game/.idea/modules.xml b/Basic Math/Odd or Even Game/.idea/modules.xml similarity index 100% rename from Odd or Even Game/.idea/modules.xml rename to Basic Math/Odd or Even Game/.idea/modules.xml diff --git a/Odd or Even Game/.idea/vcs.xml b/Basic Math/Odd or Even Game/.idea/vcs.xml similarity index 100% rename from Odd or Even Game/.idea/vcs.xml rename to Basic Math/Odd or Even Game/.idea/vcs.xml diff --git a/Odd or Even Game/.idea/workspace.xml b/Basic Math/Odd or Even Game/.idea/workspace.xml similarity index 100% rename from Odd or Even Game/.idea/workspace.xml rename to Basic Math/Odd or Even Game/.idea/workspace.xml diff --git a/Odd or Even Game/OddEvenGame.txt b/Basic Math/Odd or Even Game/OddEvenGame.txt similarity index 100% rename from Odd or Even Game/OddEvenGame.txt rename to Basic Math/Odd or Even Game/OddEvenGame.txt diff --git a/Odd or Even Game/oddEvenGame.py b/Basic Math/Odd or Even Game/oddEvenGame.py similarity index 100% rename from Odd or Even Game/oddEvenGame.py rename to Basic Math/Odd or Even Game/oddEvenGame.py diff --git a/PROXY/question.txt b/Basic Math/PROXY/question.txt similarity index 100% rename from PROXY/question.txt rename to Basic Math/PROXY/question.txt diff --git a/PROXY/solution.cpp b/Basic Math/PROXY/solution.cpp similarity index 100% rename from PROXY/solution.cpp rename to Basic Math/PROXY/solution.cpp diff --git a/Prime_gen/Prime Generator(prime_gen) b/Basic Math/Prime_gen/Prime Generator(prime_gen) similarity index 100% rename from Prime_gen/Prime Generator(prime_gen) rename to Basic Math/Prime_gen/Prime Generator(prime_gen) diff --git a/Prime_gen/prime_gen.cpp b/Basic Math/Prime_gen/prime_gen.cpp similarity index 100% rename from Prime_gen/prime_gen.cpp rename to Basic Math/Prime_gen/prime_gen.cpp diff --git a/Save the Prisoner!/question.txt b/Basic Math/Save the Prisoner!/question.txt similarity index 100% rename from Save the Prisoner!/question.txt rename to Basic Math/Save the Prisoner!/question.txt diff --git a/Save the Prisoner!/solution.cpp b/Basic Math/Save the Prisoner!/solution.cpp similarity index 100% rename from Save the Prisoner!/solution.cpp rename to Basic Math/Save the Prisoner!/solution.cpp diff --git a/Sherlock-and-the-beast/Sherlock-and-the-beast-problem.md b/Basic Math/Sherlock-and-the-beast/Sherlock-and-the-beast-problem.md similarity index 100% rename from Sherlock-and-the-beast/Sherlock-and-the-beast-problem.md rename to Basic Math/Sherlock-and-the-beast/Sherlock-and-the-beast-problem.md diff --git a/Sherlock-and-the-beast/solution.cpp b/Basic Math/Sherlock-and-the-beast/solution.cpp similarity index 94% rename from Sherlock-and-the-beast/solution.cpp rename to Basic Math/Sherlock-and-the-beast/solution.cpp index 3e7dff3..166e378 100644 --- a/Sherlock-and-the-beast/solution.cpp +++ b/Basic Math/Sherlock-and-the-beast/solution.cpp @@ -1,66 +1,66 @@ -#include - -using namespace std; - - -// Complete the decentNumber function below. - -void decent(int digits) -{ - int flag=0; - - if(digits==4 || digits==7 || digits<3) - flag=0; - else if(digits==5) - { - flag=1; - cout<<"33333\n"; - - } - else if(digits%3 ==0) - { - flag=1; - //(no. of times, what needs to be printed) - cout<=8) - { - - int remain3,remain5,temp; - - temp=digits%3; - flag=1; - if(temp==1) - { - remain5=digits-10; - remain3=10; - } - else if(temp==2) - { - remain5=digits-5; - remain3=5; - } - - cout<>cases; - while(cases-->0) - { - cin>>input; - decent(input); - } - return 0; +#include + +using namespace std; + + +// Complete the decentNumber function below. + +void decent(int digits) +{ + int flag=0; + + if(digits==4 || digits==7 || digits<3) + flag=0; + else if(digits==5) + { + flag=1; + cout<<"33333\n"; + + } + else if(digits%3 ==0) + { + flag=1; + //(no. of times, what needs to be printed) + cout<=8) + { + + int remain3,remain5,temp; + + temp=digits%3; + flag=1; + if(temp==1) + { + remain5=digits-10; + remain3=10; + } + else if(temp==2) + { + remain5=digits-5; + remain3=5; + } + + cout<>cases; + while(cases-->0) + { + cin>>input; + decent(input); + } + return 0; } \ No newline at end of file diff --git a/The Additionator/The Additionator.txt b/Basic Math/The Additionator/The Additionator.txt similarity index 100% rename from The Additionator/The Additionator.txt rename to Basic Math/The Additionator/The Additionator.txt diff --git a/The Additionator/solution.java b/Basic Math/The Additionator/solution.java similarity index 100% rename from The Additionator/solution.java rename to Basic Math/The Additionator/solution.java diff --git a/The Prime Game/Problem_statement.txt b/Basic Math/The Prime Game/Problem_statement.txt similarity index 99% rename from The Prime Game/Problem_statement.txt rename to Basic Math/The Prime Game/Problem_statement.txt index 050d2b2..062ec10 100644 --- a/The Prime Game/Problem_statement.txt +++ b/Basic Math/The Prime Game/Problem_statement.txt @@ -1,9 +1,9 @@ -Manasa loves the nim game, in which there are n buckets, each having Ai balls. Two players play alternately. Each turn consists of removing some non-zero number of balls from one of the bucket. A player with lack of moves looses. But, Manasa having played it so many times, she gets bored one day. So she wants to change the rules of the game. She loves prime numbers, so she makes a new rule: any player can only remove a prime number of balls from a bucket. But there are infinite number prime numbers. So to keep the game simple, a player can only remove x balls from a bucket if x belongs to the set - -S = {2, 3, 5, 7, 11, 13} - -The whole game can now be described as follows: - -There are buckets, and the bucket contains balls. A player can choose a bucket and remove balls from that bucket where belongs to . A player loses if there are no more available moves. - +Manasa loves the nim game, in which there are n buckets, each having Ai balls. Two players play alternately. Each turn consists of removing some non-zero number of balls from one of the bucket. A player with lack of moves looses. But, Manasa having played it so many times, she gets bored one day. So she wants to change the rules of the game. She loves prime numbers, so she makes a new rule: any player can only remove a prime number of balls from a bucket. But there are infinite number prime numbers. So to keep the game simple, a player can only remove x balls from a bucket if x belongs to the set + +S = {2, 3, 5, 7, 11, 13} + +The whole game can now be described as follows: + +There are buckets, and the bucket contains balls. A player can choose a bucket and remove balls from that bucket where belongs to . A player loses if there are no more available moves. + Manasa plays the first move against Sandy. Who will win if both of them play optimally? \ No newline at end of file diff --git a/The Prime Game/Solution.py b/Basic Math/The Prime Game/Solution.py similarity index 96% rename from The Prime Game/Solution.py rename to Basic Math/The Prime Game/Solution.py index 7ec6413..4238403 100644 --- a/The Prime Game/Solution.py +++ b/Basic Math/The Prime Game/Solution.py @@ -1,12 +1,12 @@ -s = [0, 0, 1, 1, 2, 2, 3, 3, 4] -t = int(input()) -for ti in range(t): - n = int(input()) - a = [int(ai) for ai in input().strip().split(" ")] - ans = 0 - for i in range(n): - ans = ans^s[int(a[i]%len(s))] - if(ans>0): - print("Manasa") - else: - print("Sandy") +s = [0, 0, 1, 1, 2, 2, 3, 3, 4] +t = int(input()) +for ti in range(t): + n = int(input()) + a = [int(ai) for ai in input().strip().split(" ")] + ans = 0 + for i in range(n): + ans = ans^s[int(a[i]%len(s))] + if(ans>0): + print("Manasa") + else: + print("Sandy") diff --git a/When to take medicine/problem_statement.txt b/Basic Math/When to take medicine/problem_statement.txt similarity index 100% rename from When to take medicine/problem_statement.txt rename to Basic Math/When to take medicine/problem_statement.txt diff --git a/When to take medicine/when to take medicine_answer.txt b/Basic Math/When to take medicine/when to take medicine_answer.txt similarity index 100% rename from When to take medicine/when to take medicine_answer.txt rename to Basic Math/When to take medicine/when to take medicine_answer.txt diff --git a/find_factorial_of_a_number/find_factorial_of_a_number.txt b/Basic Math/find_factorial_of_a_number/find_factorial_of_a_number.txt similarity index 100% rename from find_factorial_of_a_number/find_factorial_of_a_number.txt rename to Basic Math/find_factorial_of_a_number/find_factorial_of_a_number.txt diff --git a/find_factorial_of_a_number/solution.cpp b/Basic Math/find_factorial_of_a_number/solution.cpp similarity index 100% rename from find_factorial_of_a_number/solution.cpp rename to Basic Math/find_factorial_of_a_number/solution.cpp diff --git a/project_euler problem12/Highly divisible triangular number.cpp b/Basic Math/project_euler problem12/Highly divisible triangular number.cpp similarity index 100% rename from project_euler problem12/Highly divisible triangular number.cpp rename to Basic Math/project_euler problem12/Highly divisible triangular number.cpp diff --git a/project_euler problem12/problem b/Basic Math/project_euler problem12/problem similarity index 100% rename from project_euler problem12/problem rename to Basic Math/project_euler problem12/problem diff --git a/CollatzConjecture/CollatzConjecture.txt b/Basic Program/CollatzConjecture/CollatzConjecture.txt similarity index 100% rename from CollatzConjecture/CollatzConjecture.txt rename to Basic Program/CollatzConjecture/CollatzConjecture.txt diff --git a/CollatzConjecture/solution.c b/Basic Program/CollatzConjecture/solution.c similarity index 95% rename from CollatzConjecture/solution.c rename to Basic Program/CollatzConjecture/solution.c index 600e64a..0f667da 100644 --- a/CollatzConjecture/solution.c +++ b/Basic Program/CollatzConjecture/solution.c @@ -1,23 +1,23 @@ -#include -#include - -int main(){ - long int N = 26; //CALCULATING FOR N = 26 - long int biggestValue = 0; - long int steps = 0; - - while(N != 1){ - if(N%2 == 0){ - N = N/2; - }else{ - N = N*3 + 1; - } - if(N>biggestValue){ - biggestValue = N; - } - steps++; - } - - printf("Number of Steps: %ld BiggestValue: %ld", steps, biggestValue); - +#include +#include + +int main(){ + long int N = 26; //CALCULATING FOR N = 26 + long int biggestValue = 0; + long int steps = 0; + + while(N != 1){ + if(N%2 == 0){ + N = N/2; + }else{ + N = N*3 + 1; + } + if(N>biggestValue){ + biggestValue = N; + } + steps++; + } + + printf("Number of Steps: %ld BiggestValue: %ld", steps, biggestValue); + } \ No newline at end of file diff --git a/EncoderProblem/Encoder.java b/Basic Program/EncoderProblem/Encoder.java similarity index 100% rename from EncoderProblem/Encoder.java rename to Basic Program/EncoderProblem/Encoder.java diff --git a/EncoderProblem/problem.txt b/Basic Program/EncoderProblem/problem.txt similarity index 100% rename from EncoderProblem/problem.txt rename to Basic Program/EncoderProblem/problem.txt diff --git a/Leap Year/instructions.txt b/Basic Program/Leap Year/instructions.txt similarity index 100% rename from Leap Year/instructions.txt rename to Basic Program/Leap Year/instructions.txt diff --git a/Leap Year/ruby_solution.rb b/Basic Program/Leap Year/ruby_solution.rb similarity index 100% rename from Leap Year/ruby_solution.rb rename to Basic Program/Leap Year/ruby_solution.rb diff --git a/Sleep_In/sleep_in.py b/Basic Program/Sleep_In/sleep_in.py similarity index 100% rename from Sleep_In/sleep_in.py rename to Basic Program/Sleep_In/sleep_in.py diff --git a/how-can-create-a-hackthoberfest-infinite-loop-in-python/hacktoberfest-loop.txt b/Basic Program/how-can-create-a-hackthoberfest-infinite-loop-in-python/hacktoberfest-loop.txt similarity index 100% rename from how-can-create-a-hackthoberfest-infinite-loop-in-python/hacktoberfest-loop.txt rename to Basic Program/how-can-create-a-hackthoberfest-infinite-loop-in-python/hacktoberfest-loop.txt diff --git a/how-can-create-a-hackthoberfest-infinite-loop-in-python/infinity-hscktoberfest-loop.py b/Basic Program/how-can-create-a-hackthoberfest-infinite-loop-in-python/infinity-hscktoberfest-loop.py similarity index 100% rename from how-can-create-a-hackthoberfest-infinite-loop-in-python/infinity-hscktoberfest-loop.py rename to Basic Program/how-can-create-a-hackthoberfest-infinite-loop-in-python/infinity-hscktoberfest-loop.py diff --git a/Aggressive Cows Spoj/problem statement.txt b/Binary Search/Aggressive Cows Spoj/problem statement.txt similarity index 100% rename from Aggressive Cows Spoj/problem statement.txt rename to Binary Search/Aggressive Cows Spoj/problem statement.txt diff --git a/Aggressive Cows Spoj/solution1.cpp b/Binary Search/Aggressive Cows Spoj/solution1.cpp similarity index 100% rename from Aggressive Cows Spoj/solution1.cpp rename to Binary Search/Aggressive Cows Spoj/solution1.cpp diff --git a/Aggressive Cows Spoj/solution2.cpp b/Binary Search/Aggressive Cows Spoj/solution2.cpp similarity index 100% rename from Aggressive Cows Spoj/solution2.cpp rename to Binary Search/Aggressive Cows Spoj/solution2.cpp diff --git a/binary_search/binary_search.txt b/Binary Search/binary_search/binary_search.txt similarity index 100% rename from binary_search/binary_search.txt rename to Binary Search/binary_search/binary_search.txt diff --git a/binary_search/bs.class b/Binary Search/binary_search/bs.class similarity index 100% rename from binary_search/bs.class rename to Binary Search/binary_search/bs.class diff --git a/binary_search/bs.ctxt b/Binary Search/binary_search/bs.ctxt similarity index 100% rename from binary_search/bs.ctxt rename to Binary Search/binary_search/bs.ctxt diff --git a/binary_search/bs.java b/Binary Search/binary_search/bs.java similarity index 100% rename from binary_search/bs.java rename to Binary Search/binary_search/bs.java diff --git a/binary_search/solution.cpp b/Binary Search/binary_search/solution.cpp similarity index 100% rename from binary_search/solution.cpp rename to Binary Search/binary_search/solution.cpp diff --git a/binary_search/solution.py b/Binary Search/binary_search/solution.py similarity index 100% rename from binary_search/solution.py rename to Binary Search/binary_search/solution.py diff --git a/ZOMCAV/ZOMCAV.txt b/Bitwise Operation/ZOMCAV/ZOMCAV.txt similarity index 100% rename from ZOMCAV/ZOMCAV.txt rename to Bitwise Operation/ZOMCAV/ZOMCAV.txt diff --git a/ZOMCAV/codechef.class b/Bitwise Operation/ZOMCAV/codechef.class similarity index 100% rename from ZOMCAV/codechef.class rename to Bitwise Operation/ZOMCAV/codechef.class diff --git a/ZOMCAV/codechef.ctxt b/Bitwise Operation/ZOMCAV/codechef.ctxt similarity index 100% rename from ZOMCAV/codechef.ctxt rename to Bitwise Operation/ZOMCAV/codechef.ctxt diff --git a/ZOMCAV/codechef.java b/Bitwise Operation/ZOMCAV/codechef.java similarity index 100% rename from ZOMCAV/codechef.java rename to Bitwise Operation/ZOMCAV/codechef.java diff --git a/0-1 Knapsack Problem/Question.txt b/Dynamic Programming/0-1 Knapsack Problem/Question.txt similarity index 100% rename from 0-1 Knapsack Problem/Question.txt rename to Dynamic Programming/0-1 Knapsack Problem/Question.txt diff --git a/0-1 Knapsack Problem/Solution.c b/Dynamic Programming/0-1 Knapsack Problem/Solution.c similarity index 100% rename from 0-1 Knapsack Problem/Solution.c rename to Dynamic Programming/0-1 Knapsack Problem/Solution.c diff --git a/Buy-and-Sell-Stock-for-Maximum-Profit/buyAndSellStock.py b/Dynamic Programming/Buy-and-Sell-Stock-for-Maximum-Profit/buyAndSellStock.py similarity index 100% rename from Buy-and-Sell-Stock-for-Maximum-Profit/buyAndSellStock.py rename to Dynamic Programming/Buy-and-Sell-Stock-for-Maximum-Profit/buyAndSellStock.py diff --git a/Buy-and-Sell-Stock-for-Maximum-Profit/problem-statement.txt b/Dynamic Programming/Buy-and-Sell-Stock-for-Maximum-Profit/problem-statement.txt similarity index 100% rename from Buy-and-Sell-Stock-for-Maximum-Profit/problem-statement.txt rename to Dynamic Programming/Buy-and-Sell-Stock-for-Maximum-Profit/problem-statement.txt diff --git a/Bytelandian-gold-coins/instructions.txt b/Dynamic Programming/Bytelandian-gold-coins/instructions.txt similarity index 100% rename from Bytelandian-gold-coins/instructions.txt rename to Dynamic Programming/Bytelandian-gold-coins/instructions.txt diff --git a/Bytelandian-gold-coins/solution.cpp b/Dynamic Programming/Bytelandian-gold-coins/solution.cpp similarity index 100% rename from Bytelandian-gold-coins/solution.cpp rename to Dynamic Programming/Bytelandian-gold-coins/solution.cpp diff --git a/COINS/Question.txt b/Dynamic Programming/COINS/Question.txt similarity index 100% rename from COINS/Question.txt rename to Dynamic Programming/COINS/Question.txt diff --git a/COINS/Readme.md b/Dynamic Programming/COINS/Readme.md similarity index 100% rename from COINS/Readme.md rename to Dynamic Programming/COINS/Readme.md diff --git a/COINS/Solution.cpp b/Dynamic Programming/COINS/Solution.cpp similarity index 100% rename from COINS/Solution.cpp rename to Dynamic Programming/COINS/Solution.cpp diff --git a/DP- Min Steps to 1/Min Steps to 1 Problem Statement.txt b/Dynamic Programming/DP- Min Steps to 1/Min Steps to 1 Problem Statement.txt similarity index 100% rename from DP- Min Steps to 1/Min Steps to 1 Problem Statement.txt rename to Dynamic Programming/DP- Min Steps to 1/Min Steps to 1 Problem Statement.txt diff --git a/DP- Min Steps to 1/minsteps.java b/Dynamic Programming/DP- Min Steps to 1/minsteps.java similarity index 100% rename from DP- Min Steps to 1/minsteps.java rename to Dynamic Programming/DP- Min Steps to 1/minsteps.java diff --git a/Magic-Spells-LCS/problem.txt b/Dynamic Programming/Magic-Spells-LCS/problem.txt similarity index 100% rename from Magic-Spells-LCS/problem.txt rename to Dynamic Programming/Magic-Spells-LCS/problem.txt diff --git a/Magic-Spells-LCS/solution.cpp b/Dynamic Programming/Magic-Spells-LCS/solution.cpp similarity index 100% rename from Magic-Spells-LCS/solution.cpp rename to Dynamic Programming/Magic-Spells-LCS/solution.cpp diff --git a/Max_Sum_Contiguous_Subarray/Question.txt b/Dynamic Programming/Max_Sum_Contiguous_Subarray/Question.txt similarity index 100% rename from Max_Sum_Contiguous_Subarray/Question.txt rename to Dynamic Programming/Max_Sum_Contiguous_Subarray/Question.txt diff --git a/Max_Sum_Contiguous_Subarray/Readme.md b/Dynamic Programming/Max_Sum_Contiguous_Subarray/Readme.md similarity index 100% rename from Max_Sum_Contiguous_Subarray/Readme.md rename to Dynamic Programming/Max_Sum_Contiguous_Subarray/Readme.md diff --git a/Max_Sum_Contiguous_Subarray/Solution.cpp b/Dynamic Programming/Max_Sum_Contiguous_Subarray/Solution.cpp similarity index 100% rename from Max_Sum_Contiguous_Subarray/Solution.cpp rename to Dynamic Programming/Max_Sum_Contiguous_Subarray/Solution.cpp diff --git a/Maximize the Product/Maximize the product.txt b/Dynamic Programming/Maximize the Product/Maximize the product.txt similarity index 100% rename from Maximize the Product/Maximize the product.txt rename to Dynamic Programming/Maximize the Product/Maximize the product.txt diff --git a/Maximize the Product/solution.cpp b/Dynamic Programming/Maximize the Product/solution.cpp similarity index 100% rename from Maximize the Product/solution.cpp rename to Dynamic Programming/Maximize the Product/solution.cpp diff --git a/Maximum sum of digits/code.cpp b/Dynamic Programming/Maximum sum of digits/code.cpp similarity index 100% rename from Maximum sum of digits/code.cpp rename to Dynamic Programming/Maximum sum of digits/code.cpp diff --git a/Maximum sum of digits/problem_statement.txt b/Dynamic Programming/Maximum sum of digits/problem_statement.txt similarity index 100% rename from Maximum sum of digits/problem_statement.txt rename to Dynamic Programming/Maximum sum of digits/problem_statement.txt diff --git a/Maximum-Perimeter-Triangle/Maximum-Perimeter-Triangle-Problem b/Dynamic Programming/Maximum-Perimeter-Triangle/Maximum-Perimeter-Triangle-Problem similarity index 100% rename from Maximum-Perimeter-Triangle/Maximum-Perimeter-Triangle-Problem rename to Dynamic Programming/Maximum-Perimeter-Triangle/Maximum-Perimeter-Triangle-Problem diff --git a/Maximum-Perimeter-Triangle/Solution.cpp b/Dynamic Programming/Maximum-Perimeter-Triangle/Solution.cpp similarity index 100% rename from Maximum-Perimeter-Triangle/Solution.cpp rename to Dynamic Programming/Maximum-Perimeter-Triangle/Solution.cpp diff --git a/Powerset/powerset.js b/Dynamic Programming/Powerset/powerset.js similarity index 100% rename from Powerset/powerset.js rename to Dynamic Programming/Powerset/powerset.js diff --git a/Powerset/question.txt b/Dynamic Programming/Powerset/question.txt similarity index 100% rename from Powerset/question.txt rename to Dynamic Programming/Powerset/question.txt diff --git a/Prime_subsequence/question.txt b/Dynamic Programming/Prime_subsequence/question.txt similarity index 100% rename from Prime_subsequence/question.txt rename to Dynamic Programming/Prime_subsequence/question.txt diff --git a/Prime_subsequence/solution.cpp b/Dynamic Programming/Prime_subsequence/solution.cpp similarity index 100% rename from Prime_subsequence/solution.cpp rename to Dynamic Programming/Prime_subsequence/solution.cpp diff --git a/ROCK/problem.txt b/Dynamic Programming/ROCK/problem.txt similarity index 100% rename from ROCK/problem.txt rename to Dynamic Programming/ROCK/problem.txt diff --git a/ROCK/rock.cpp b/Dynamic Programming/ROCK/rock.cpp similarity index 100% rename from ROCK/rock.cpp rename to Dynamic Programming/ROCK/rock.cpp diff --git a/Rod cutting problem/question.txt b/Dynamic Programming/Rod cutting problem/question.txt similarity index 100% rename from Rod cutting problem/question.txt rename to Dynamic Programming/Rod cutting problem/question.txt diff --git a/Rod cutting problem/solution.java b/Dynamic Programming/Rod cutting problem/solution.java similarity index 100% rename from Rod cutting problem/solution.java rename to Dynamic Programming/Rod cutting problem/solution.java diff --git a/The Mailbox Manufacturers Problem/mailbox-question.txt b/Dynamic Programming/The Mailbox Manufacturers Problem/mailbox-question.txt similarity index 100% rename from The Mailbox Manufacturers Problem/mailbox-question.txt rename to Dynamic Programming/The Mailbox Manufacturers Problem/mailbox-question.txt diff --git a/The Mailbox Manufacturers Problem/solution.cpp b/Dynamic Programming/The Mailbox Manufacturers Problem/solution.cpp similarity index 100% rename from The Mailbox Manufacturers Problem/solution.cpp rename to Dynamic Programming/The Mailbox Manufacturers Problem/solution.cpp diff --git a/Zero_Sum_SubArray/question.txt b/Dynamic Programming/Zero_Sum_SubArray/question.txt similarity index 100% rename from Zero_Sum_SubArray/question.txt rename to Dynamic Programming/Zero_Sum_SubArray/question.txt diff --git a/Zero_Sum_SubArray/solution.cpp b/Dynamic Programming/Zero_Sum_SubArray/solution.cpp similarity index 100% rename from Zero_Sum_SubArray/solution.cpp rename to Dynamic Programming/Zero_Sum_SubArray/solution.cpp diff --git a/alphacode/problem_statement.txt b/Dynamic Programming/alphacode/problem_statement.txt similarity index 100% rename from alphacode/problem_statement.txt rename to Dynamic Programming/alphacode/problem_statement.txt diff --git a/alphacode/solution.txt b/Dynamic Programming/alphacode/solution.txt similarity index 100% rename from alphacode/solution.txt rename to Dynamic Programming/alphacode/solution.txt diff --git a/Product_of_lengths_all_cycles_undirected_graph/question.txt b/Graph/Product_of_lengths_all_cycles_undirected_graph/question.txt similarity index 100% rename from Product_of_lengths_all_cycles_undirected_graph/question.txt rename to Graph/Product_of_lengths_all_cycles_undirected_graph/question.txt diff --git a/Product_of_lengths_all_cycles_undirected_graph/solution.cpp b/Graph/Product_of_lengths_all_cycles_undirected_graph/solution.cpp similarity index 100% rename from Product_of_lengths_all_cycles_undirected_graph/solution.cpp rename to Graph/Product_of_lengths_all_cycles_undirected_graph/solution.cpp diff --git a/The_Coin_Change_Problem/Problem_Statement.txt b/Greedy/The_Coin_Change_Problem/Problem_Statement.txt similarity index 100% rename from The_Coin_Change_Problem/Problem_Statement.txt rename to Greedy/The_Coin_Change_Problem/Problem_Statement.txt diff --git a/The_Coin_Change_Problem/Solution.java b/Greedy/The_Coin_Change_Problem/Solution.java similarity index 100% rename from The_Coin_Change_Problem/Solution.java rename to Greedy/The_Coin_Change_Problem/Solution.java diff --git a/Implement a Line Editor with a Linked List/Problem Statement.txt b/LinkedList/Implement a Line Editor with a Linked List/Problem Statement.txt similarity index 100% rename from Implement a Line Editor with a Linked List/Problem Statement.txt rename to LinkedList/Implement a Line Editor with a Linked List/Problem Statement.txt diff --git a/Implement a Line Editor with a Linked List/Solution.cpp b/LinkedList/Implement a Line Editor with a Linked List/Solution.cpp similarity index 100% rename from Implement a Line Editor with a Linked List/Solution.cpp rename to LinkedList/Implement a Line Editor with a Linked List/Solution.cpp diff --git a/AAL/Aditya And Ladders.txt b/Patterns/AAL/Aditya And Ladders.txt similarity index 100% rename from AAL/Aditya And Ladders.txt rename to Patterns/AAL/Aditya And Ladders.txt diff --git a/AAL/x.cpp b/Patterns/AAL/x.cpp similarity index 100% rename from AAL/x.cpp rename to Patterns/AAL/x.cpp diff --git a/PatternPrinting/README.md b/Patterns/PatternPrinting/README.md similarity index 100% rename from PatternPrinting/README.md rename to Patterns/PatternPrinting/README.md diff --git a/PatternPrinting/sum.java b/Patterns/PatternPrinting/sum.java similarity index 95% rename from PatternPrinting/sum.java rename to Patterns/PatternPrinting/sum.java index d211336..292e80b 100644 --- a/PatternPrinting/sum.java +++ b/Patterns/PatternPrinting/sum.java @@ -1,36 +1,36 @@ -class Sum{ - public void print(int arr[],int n) - { - int b[] = new int[arr.length-1]; - if(arr.length>1) - { - for(int i =0;i1) + { + for(int i =0;i -using namespace std; - -void copyArr(int from[], int si, int ei, int * to) { - // while (si <= ei) *to++ = *si++; - while (si <= ei) { - *to = from[si]; - ++si; - ++to; - } -} - - -void mergeSortedArray(int arr[], int si, int ei, int mid) { - - int tmp_A[100]; - int tmp_B[100]; - - copyArr(arr, si, mid, tmp_A); - copyArr(arr, mid + 1, ei, tmp_B); - - int i = 0; - int j = 0; - int k = si; - - //while a has elements and b has elements, I have to do something - int size_A = mid - si + 1; - int size_B = ei - (mid + 1) + 1; - - while (i < size_A && j < size_B) { - if (tmp_A[i] < tmp_B[j]) { - arr[k] = tmp_A[i]; - i++; - k++; - } - else { - arr[k++] = tmp_B[j++]; - } - } - - while (i < size_A) { - arr[k++] = tmp_A[i++]; - } - - while (j < size_B) arr[k++] = tmp_B[j++]; - - -} - - -void mergeSort(int arr[], int si, int ei) { - if (si >= ei) { - //no elements - return; - } - - int mid = (si + ei) / 2; - //sort the left part - mergeSort(arr, si, mid); - mergeSort(arr, mid + 1, ei); - - mergeSortedArray(arr, si, ei, mid); - -} - - -int main() { - int arr[100]; - int n; - cin >> n; - inputArr(arr, n); - - mergeSort(arr, 0, n - 1); - - printArr(arr, n); -} + +#include "../helper.h" +#include +using namespace std; + +void copyArr(int from[], int si, int ei, int * to) { + // while (si <= ei) *to++ = *si++; + while (si <= ei) { + *to = from[si]; + ++si; + ++to; + } +} + + +void mergeSortedArray(int arr[], int si, int ei, int mid) { + + int tmp_A[100]; + int tmp_B[100]; + + copyArr(arr, si, mid, tmp_A); + copyArr(arr, mid + 1, ei, tmp_B); + + int i = 0; + int j = 0; + int k = si; + + //while a has elements and b has elements, I have to do something + int size_A = mid - si + 1; + int size_B = ei - (mid + 1) + 1; + + while (i < size_A && j < size_B) { + if (tmp_A[i] < tmp_B[j]) { + arr[k] = tmp_A[i]; + i++; + k++; + } + else { + arr[k++] = tmp_B[j++]; + } + } + + while (i < size_A) { + arr[k++] = tmp_A[i++]; + } + + while (j < size_B) arr[k++] = tmp_B[j++]; + + +} + + +void mergeSort(int arr[], int si, int ei) { + if (si >= ei) { + //no elements + return; + } + + int mid = (si + ei) / 2; + //sort the left part + mergeSort(arr, si, mid); + mergeSort(arr, mid + 1, ei); + + mergeSortedArray(arr, si, ei, mid); + +} + + +int main() { + int arr[100]; + int n; + cin >> n; + inputArr(arr, n); + + mergeSort(arr, 0, n - 1); + + printArr(arr, n); +} diff --git a/Mersort_In_C++/mergesort.txt b/Sorting/Mersort_In_C++/mergesort.txt similarity index 100% rename from Mersort_In_C++/mergesort.txt rename to Sorting/Mersort_In_C++/mergesort.txt diff --git a/Quicksort-JS/question.txt b/Sorting/Quicksort-JS/question.txt similarity index 100% rename from Quicksort-JS/question.txt rename to Sorting/Quicksort-JS/question.txt diff --git a/Quicksort-JS/quickSort.js b/Sorting/Quicksort-JS/quickSort.js similarity index 100% rename from Quicksort-JS/quickSort.js rename to Sorting/Quicksort-JS/quickSort.js diff --git a/Quicksort-python/Question.txt b/Sorting/Quicksort-python/Question.txt similarity index 100% rename from Quicksort-python/Question.txt rename to Sorting/Quicksort-python/Question.txt diff --git a/Quicksort-python/algorithm.txt b/Sorting/Quicksort-python/algorithm.txt similarity index 100% rename from Quicksort-python/algorithm.txt rename to Sorting/Quicksort-python/algorithm.txt diff --git a/Quicksort-python/quickSort.py b/Sorting/Quicksort-python/quickSort.py old mode 100755 new mode 100644 similarity index 100% rename from Quicksort-python/quickSort.py rename to Sorting/Quicksort-python/quickSort.py diff --git a/bubble_sort_c/question.txt b/Sorting/bubble_sort_c/question.txt similarity index 100% rename from bubble_sort_c/question.txt rename to Sorting/bubble_sort_c/question.txt diff --git a/bubble_sort_c/solution/bubble_sort.c b/Sorting/bubble_sort_c/solution/bubble_sort.c similarity index 100% rename from bubble_sort_c/solution/bubble_sort.c rename to Sorting/bubble_sort_c/solution/bubble_sort.c diff --git a/bubble_sort_c/solution/bubble_sort.h b/Sorting/bubble_sort_c/solution/bubble_sort.h similarity index 100% rename from bubble_sort_c/solution/bubble_sort.h rename to Sorting/bubble_sort_c/solution/bubble_sort.h diff --git a/bubble_sort_c/solution/main.c b/Sorting/bubble_sort_c/solution/main.c similarity index 100% rename from bubble_sort_c/solution/main.c rename to Sorting/bubble_sort_c/solution/main.c diff --git a/bubble_sort_c/solution/print_array.c b/Sorting/bubble_sort_c/solution/print_array.c similarity index 100% rename from bubble_sort_c/solution/print_array.c rename to Sorting/bubble_sort_c/solution/print_array.c diff --git a/Generate Parentheses/Question.txt b/Stack/Generate Parentheses/Question.txt similarity index 100% rename from Generate Parentheses/Question.txt rename to Stack/Generate Parentheses/Question.txt diff --git a/Generate Parentheses/Solution b/Stack/Generate Parentheses/Solution old mode 100755 new mode 100644 similarity index 100% rename from Generate Parentheses/Solution rename to Stack/Generate Parentheses/Solution diff --git a/Generate Parentheses/Solution.cpp b/Stack/Generate Parentheses/Solution.cpp similarity index 100% rename from Generate Parentheses/Solution.cpp rename to Stack/Generate Parentheses/Solution.cpp diff --git a/Street parade/code.cpp b/Stack/Street parade/code.cpp similarity index 100% rename from Street parade/code.cpp rename to Stack/Street parade/code.cpp diff --git a/Street parade/problem_statement.txt b/Stack/Street parade/problem_statement.txt similarity index 100% rename from Street parade/problem_statement.txt rename to Stack/Street parade/problem_statement.txt diff --git a/AnagramChecking/anagram_checking.py b/String/AnagramChecking/anagram_checking.py old mode 100755 new mode 100644 similarity index 100% rename from AnagramChecking/anagram_checking.py rename to String/AnagramChecking/anagram_checking.py diff --git a/AnagramChecking/anagram_checking.txt b/String/AnagramChecking/anagram_checking.txt similarity index 100% rename from AnagramChecking/anagram_checking.txt rename to String/AnagramChecking/anagram_checking.txt diff --git a/Arrangement_of_Queue/Question.txt b/String/Arrangement_of_Queue/Question.txt similarity index 100% rename from Arrangement_of_Queue/Question.txt rename to String/Arrangement_of_Queue/Question.txt diff --git a/Arrangement_of_Queue/README.md b/String/Arrangement_of_Queue/README.md similarity index 100% rename from Arrangement_of_Queue/README.md rename to String/Arrangement_of_Queue/README.md diff --git a/Arrangement_of_Queue/Solution.py b/String/Arrangement_of_Queue/Solution.py similarity index 100% rename from Arrangement_of_Queue/Solution.py rename to String/Arrangement_of_Queue/Solution.py diff --git a/Cenit-Polar-Crypt/Issue.txt b/String/Cenit-Polar-Crypt/Issue.txt similarity index 100% rename from Cenit-Polar-Crypt/Issue.txt rename to String/Cenit-Polar-Crypt/Issue.txt diff --git a/Cenit-Polar-Crypt/Solution.js b/String/Cenit-Polar-Crypt/Solution.js similarity index 100% rename from Cenit-Polar-Crypt/Solution.js rename to String/Cenit-Polar-Crypt/Solution.js diff --git a/Check_String_Palindrome/Source1.cpp b/String/Check_String_Palindrome/Source1.cpp similarity index 100% rename from Check_String_Palindrome/Source1.cpp rename to String/Check_String_Palindrome/Source1.cpp diff --git a/Check_String_Palindrome/problem.txt b/String/Check_String_Palindrome/problem.txt similarity index 100% rename from Check_String_Palindrome/problem.txt rename to String/Check_String_Palindrome/problem.txt diff --git a/FANCY/problem.txt b/String/FANCY/problem.txt similarity index 100% rename from FANCY/problem.txt rename to String/FANCY/problem.txt diff --git a/FANCY/solution.py b/String/FANCY/solution.py similarity index 100% rename from FANCY/solution.py rename to String/FANCY/solution.py diff --git a/Isograms/isograms.py b/String/Isograms/isograms.py similarity index 100% rename from Isograms/isograms.py rename to String/Isograms/isograms.py diff --git a/Isograms/problem_statement.txt b/String/Isograms/problem_statement.txt similarity index 100% rename from Isograms/problem_statement.txt rename to String/Isograms/problem_statement.txt diff --git a/Palindrome/palindrome.c b/String/Palindrome/palindrome.c similarity index 100% rename from Palindrome/palindrome.c rename to String/Palindrome/palindrome.c diff --git a/Palindrome/question.txt b/String/Palindrome/question.txt similarity index 100% rename from Palindrome/question.txt rename to String/Palindrome/question.txt diff --git a/Python_Palindrome/PalindromeQues.txt b/String/Python_Palindrome/PalindromeQues.txt similarity index 100% rename from Python_Palindrome/PalindromeQues.txt rename to String/Python_Palindrome/PalindromeQues.txt diff --git a/Python_Palindrome/solution.py b/String/Python_Palindrome/solution.py similarity index 100% rename from Python_Palindrome/solution.py rename to String/Python_Palindrome/solution.py diff --git a/Reverse string in place/question.txt b/String/Reverse string in place/question.txt similarity index 100% rename from Reverse string in place/question.txt rename to String/Reverse string in place/question.txt diff --git a/Reverse string in place/solution.java b/String/Reverse string in place/solution.java similarity index 100% rename from Reverse string in place/solution.java rename to String/Reverse string in place/solution.java diff --git a/ReverseChars/ReverseChars.java b/String/ReverseChars/ReverseChars.java similarity index 95% rename from ReverseChars/ReverseChars.java rename to String/ReverseChars/ReverseChars.java index 75aa58d..bd0c68e 100644 --- a/ReverseChars/ReverseChars.java +++ b/String/ReverseChars/ReverseChars.java @@ -1,26 +1,26 @@ -class main { - - public static void main(String[] args){ - - System.out.println(reverseChars("These Chars will be in reverse")); - - } - - public static String reverseChars(String reverseIt) { - - int stringLength; - String itReversed; - - reverseIt = reverseIt; - - stringLength = reverseIt.length(); - itReversed = ""; - - for (int i = 1; i <= stringLength; i++){ - char backwardChars = reverseIt.charAt(stringLength - i); - - itReversed += backwardChars; - } - return itReversed; - } +class main { + + public static void main(String[] args){ + + System.out.println(reverseChars("These Chars will be in reverse")); + + } + + public static String reverseChars(String reverseIt) { + + int stringLength; + String itReversed; + + reverseIt = reverseIt; + + stringLength = reverseIt.length(); + itReversed = ""; + + for (int i = 1; i <= stringLength; i++){ + char backwardChars = reverseIt.charAt(stringLength - i); + + itReversed += backwardChars; + } + return itReversed; + } } \ No newline at end of file diff --git a/ReverseChars/problem.txt b/String/ReverseChars/problem.txt similarity index 100% rename from ReverseChars/problem.txt rename to String/ReverseChars/problem.txt diff --git a/SplitString/Question.txt b/String/SplitString/Question.txt similarity index 100% rename from SplitString/Question.txt rename to String/SplitString/Question.txt diff --git a/SplitString/Solution.cpp b/String/SplitString/Solution.cpp similarity index 100% rename from SplitString/Solution.cpp rename to String/SplitString/Solution.cpp diff --git a/String_Permutation/question.txt b/String/String_Permutation/question.txt similarity index 100% rename from String_Permutation/question.txt rename to String/String_Permutation/question.txt diff --git a/String_Permutation/solution.cpp b/String/String_Permutation/solution.cpp similarity index 100% rename from String_Permutation/solution.cpp rename to String/String_Permutation/solution.cpp diff --git a/StrongPassword/solution.py b/String/StrongPassword/solution.py similarity index 100% rename from StrongPassword/solution.py rename to String/StrongPassword/solution.py diff --git a/StrongPassword/strongpasswordqn.txt b/String/StrongPassword/strongpasswordqn.txt similarity index 100% rename from StrongPassword/strongpasswordqn.txt rename to String/StrongPassword/strongpasswordqn.txt diff --git a/Subsequences/question.txt b/String/Subsequences/question.txt similarity index 100% rename from Subsequences/question.txt rename to String/Subsequences/question.txt diff --git a/Subsequences/subsequences.cpp b/String/Subsequences/subsequences.cpp old mode 100755 new mode 100644 similarity index 94% rename from Subsequences/subsequences.cpp rename to String/Subsequences/subsequences.cpp index b445c4f..9c0ec8c --- a/Subsequences/subsequences.cpp +++ b/String/Subsequences/subsequences.cpp @@ -1,27 +1,27 @@ -//find all the sub sequences of a string -#include -using namespace std; -char output[100] = ""; - -void printSubSeq(char str[], int be, int idx) -{ - if (str[be] == '\0') - { - output[idx] = '\0'; - cout << output << endl; - return; - } - - printSubSeq(str, be + 1, idx); - output[idx] = str[be]; - printSubSeq(str, be + 1, idx + 1); -} - - -int main() { - char str[100]; - cin >> str; - - - printSubSeq(str, 0, 0); -} +//find all the sub sequences of a string +#include +using namespace std; +char output[100] = ""; + +void printSubSeq(char str[], int be, int idx) +{ + if (str[be] == '\0') + { + output[idx] = '\0'; + cout << output << endl; + return; + } + + printSubSeq(str, be + 1, idx); + output[idx] = str[be]; + printSubSeq(str, be + 1, idx + 1); +} + + +int main() { + char str[100]; + cin >> str; + + + printSubSeq(str, 0, 0); +} diff --git a/The Reversed World/Solution.cpp b/String/The Reversed World/Solution.cpp similarity index 100% rename from The Reversed World/Solution.cpp rename to String/The Reversed World/Solution.cpp diff --git a/The Reversed World/The Reversed World.txt b/String/The Reversed World/The Reversed World.txt similarity index 100% rename from The Reversed World/The Reversed World.txt rename to String/The Reversed World/The Reversed World.txt diff --git a/ToyObsession/problem.c b/String/ToyObsession/problem.c similarity index 100% rename from ToyObsession/problem.c rename to String/ToyObsession/problem.c diff --git a/ToyObsession/solution.c b/String/ToyObsession/solution.c similarity index 100% rename from ToyObsession/solution.c rename to String/ToyObsession/solution.c diff --git a/Word_Frequency/question.txt b/String/Word_Frequency/question.txt similarity index 100% rename from Word_Frequency/question.txt rename to String/Word_Frequency/question.txt diff --git a/Word_Frequency/solution.js b/String/Word_Frequency/solution.js similarity index 100% rename from Word_Frequency/solution.js rename to String/Word_Frequency/solution.js diff --git a/ginortS/Question.txt b/String/ginortS/Question.txt similarity index 100% rename from ginortS/Question.txt rename to String/ginortS/Question.txt diff --git a/ginortS/Solution.py b/String/ginortS/Solution.py similarity index 100% rename from ginortS/Solution.py rename to String/ginortS/Solution.py diff --git a/size-of-tree-C++/problem_statement.txt b/Tree/size-of-tree-C++/problem_statement.txt similarity index 100% rename from size-of-tree-C++/problem_statement.txt rename to Tree/size-of-tree-C++/problem_statement.txt diff --git a/size-of-tree-C++/sizeoftree.cpp b/Tree/size-of-tree-C++/sizeoftree.cpp similarity index 100% rename from size-of-tree-C++/sizeoftree.cpp rename to Tree/size-of-tree-C++/sizeoftree.cpp diff --git a/Acronym/instructions.txt b/Unknown/Acronym/instructions.txt similarity index 100% rename from Acronym/instructions.txt rename to Unknown/Acronym/instructions.txt diff --git a/Acronym/ruby_solution.rb b/Unknown/Acronym/ruby_solution.rb similarity index 100% rename from Acronym/ruby_solution.rb rename to Unknown/Acronym/ruby_solution.rb diff --git a/CONTON/QUESTION.txt b/Unknown/CONTON/QUESTION.txt similarity index 100% rename from CONTON/QUESTION.txt rename to Unknown/CONTON/QUESTION.txt diff --git a/CONTON/solution.c b/Unknown/CONTON/solution.c similarity index 100% rename from CONTON/solution.c rename to Unknown/CONTON/solution.c diff --git a/Chefdil/ans.cpp b/Unknown/Chefdil/ans.cpp similarity index 100% rename from Chefdil/ans.cpp rename to Unknown/Chefdil/ans.cpp diff --git a/Chefdil/ques.txt b/Unknown/Chefdil/ques.txt similarity index 100% rename from Chefdil/ques.txt rename to Unknown/Chefdil/ques.txt diff --git a/Chocolate_SPOJ/question.txt b/Unknown/Chocolate_SPOJ/question.txt similarity index 100% rename from Chocolate_SPOJ/question.txt rename to Unknown/Chocolate_SPOJ/question.txt diff --git a/Chocolate_SPOJ/solution.java b/Unknown/Chocolate_SPOJ/solution.java similarity index 100% rename from Chocolate_SPOJ/solution.java rename to Unknown/Chocolate_SPOJ/solution.java diff --git a/Fair Rations/Answer.cpp b/Unknown/Fair Rations/Answer.cpp similarity index 100% rename from Fair Rations/Answer.cpp rename to Unknown/Fair Rations/Answer.cpp diff --git a/Fair Rations/Problem Statement .txt b/Unknown/Fair Rations/Problem Statement .txt similarity index 100% rename from Fair Rations/Problem Statement .txt rename to Unknown/Fair Rations/Problem Statement .txt diff --git a/Industrial Nim/Industrial_Nim.cpp b/Unknown/Industrial Nim/Industrial_Nim.cpp similarity index 100% rename from Industrial Nim/Industrial_Nim.cpp rename to Unknown/Industrial Nim/Industrial_Nim.cpp diff --git a/Industrial Nim/Industrial_Nim.txt b/Unknown/Industrial Nim/Industrial_Nim.txt similarity index 100% rename from Industrial Nim/Industrial_Nim.txt rename to Unknown/Industrial Nim/Industrial_Nim.txt diff --git a/Necklace/solution.cpp b/Unknown/Necklace/solution.cpp similarity index 100% rename from Necklace/solution.cpp rename to Unknown/Necklace/solution.cpp diff --git a/Necklace/statement.pdf b/Unknown/Necklace/statement.pdf similarity index 100% rename from Necklace/statement.pdf rename to Unknown/Necklace/statement.pdf diff --git a/PINS/problem.txt b/Unknown/PINS/problem.txt similarity index 100% rename from PINS/problem.txt rename to Unknown/PINS/problem.txt diff --git a/PINS/solution.cpp b/Unknown/PINS/solution.cpp similarity index 100% rename from PINS/solution.cpp rename to Unknown/PINS/solution.cpp diff --git a/PolyMul/question.txt b/Unknown/PolyMul/question.txt similarity index 100% rename from PolyMul/question.txt rename to Unknown/PolyMul/question.txt diff --git a/PolyMul/solution.cpp b/Unknown/PolyMul/solution.cpp similarity index 100% rename from PolyMul/solution.cpp rename to Unknown/PolyMul/solution.cpp diff --git a/Strange_Food_Chain/question.txt b/Unknown/Strange_Food_Chain/question.txt similarity index 100% rename from Strange_Food_Chain/question.txt rename to Unknown/Strange_Food_Chain/question.txt diff --git a/Strange_Food_Chain/solution.cpp b/Unknown/Strange_Food_Chain/solution.cpp similarity index 100% rename from Strange_Food_Chain/solution.cpp rename to Unknown/Strange_Food_Chain/solution.cpp diff --git a/WATCHFB/Main.class b/Unknown/WATCHFB/Main.class similarity index 100% rename from WATCHFB/Main.class rename to Unknown/WATCHFB/Main.class diff --git a/WATCHFB/Main.ctxt b/Unknown/WATCHFB/Main.ctxt similarity index 100% rename from WATCHFB/Main.ctxt rename to Unknown/WATCHFB/Main.ctxt diff --git a/WATCHFB/Main.java b/Unknown/WATCHFB/Main.java similarity index 100% rename from WATCHFB/Main.java rename to Unknown/WATCHFB/Main.java diff --git a/WATCHFB/WATCHFB.txt b/Unknown/WATCHFB/WATCHFB.txt similarity index 100% rename from WATCHFB/WATCHFB.txt rename to Unknown/WATCHFB/WATCHFB.txt diff --git a/chusky_adventurer/problem_statement.txt b/Unknown/chusky_adventurer/problem_statement.txt similarity index 100% rename from chusky_adventurer/problem_statement.txt rename to Unknown/chusky_adventurer/problem_statement.txt diff --git a/chusky_adventurer/solution.cpp b/Unknown/chusky_adventurer/solution.cpp similarity index 100% rename from chusky_adventurer/solution.cpp rename to Unknown/chusky_adventurer/solution.cpp diff --git a/chusky_hunger/problem_statement.txt b/Unknown/chusky_hunger/problem_statement.txt similarity index 100% rename from chusky_hunger/problem_statement.txt rename to Unknown/chusky_hunger/problem_statement.txt diff --git a/chusky_hunger/solution.cpp b/Unknown/chusky_hunger/solution.cpp similarity index 100% rename from chusky_hunger/solution.cpp rename to Unknown/chusky_hunger/solution.cpp diff --git a/chusky_nightgame/problem_statement.txt b/Unknown/chusky_nightgame/problem_statement.txt similarity index 100% rename from chusky_nightgame/problem_statement.txt rename to Unknown/chusky_nightgame/problem_statement.txt diff --git a/chusky_nightgame/solution.cpp b/Unknown/chusky_nightgame/solution.cpp similarity index 100% rename from chusky_nightgame/solution.cpp rename to Unknown/chusky_nightgame/solution.cpp diff --git a/coin-piles/problem_statement.txt b/Unknown/coin-piles/problem_statement.txt similarity index 100% rename from coin-piles/problem_statement.txt rename to Unknown/coin-piles/problem_statement.txt diff --git a/coin-piles/solution.cpp b/Unknown/coin-piles/solution.cpp similarity index 100% rename from coin-piles/solution.cpp rename to Unknown/coin-piles/solution.cpp From aafa1356e8a5eba80dc338e98721f2049128d405 Mon Sep 17 00:00:00 2001 From: syk007 Date: Sat, 10 Oct 2020 20:32:23 +0530 Subject: [PATCH 098/109] Added A greedy problem: Cutting a Rod --- Greedy/Cutting_a_Rod/CuttingARod.java | 33 ++++++++++++++++++++++ Greedy/Cutting_a_Rod/Problem_Statement.txt | 8 ++++++ 2 files changed, 41 insertions(+) create mode 100644 Greedy/Cutting_a_Rod/CuttingARod.java create mode 100644 Greedy/Cutting_a_Rod/Problem_Statement.txt diff --git a/Greedy/Cutting_a_Rod/CuttingARod.java b/Greedy/Cutting_a_Rod/CuttingARod.java new file mode 100644 index 0000000..8a29c87 --- /dev/null +++ b/Greedy/Cutting_a_Rod/CuttingARod.java @@ -0,0 +1,33 @@ +/** + * Time Complexity : O(n^2) + * which is much better than the + * worst case time complexity of Naive Recursive implementation. + */ + +import java.util.*; +import java.io.*; + +class CuttingARod { + + public static int cutCutCut(int price[], int size) { + + int memory[] = new int[size+1]; + memory[0] = 0; + + for(int i=1; i<=size; i++){ + int maximum = Integer.MIN_VALUE; + for(int j=0; j Date: Mon, 12 Oct 2020 15:02:15 +0530 Subject: [PATCH 099/109] A simple question on 2D array --- .../Hourglass in Array/Hourglass in Array.txt | 59 +++++++++++++++++++ Array/Hourglass in Array/Solution.cpp | 58 ++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 Array/Hourglass in Array/Hourglass in Array.txt create mode 100644 Array/Hourglass in Array/Solution.cpp diff --git a/Array/Hourglass in Array/Hourglass in Array.txt b/Array/Hourglass in Array/Hourglass in Array.txt new file mode 100644 index 0000000..7360172 --- /dev/null +++ b/Array/Hourglass in Array/Hourglass in Array.txt @@ -0,0 +1,59 @@ +Given a 6x6 2D Array, arr: + +1 1 1 0 0 0 +0 1 0 0 0 0 +1 1 1 0 0 0 +0 0 0 0 0 0 +0 0 0 0 0 0 +0 0 0 0 0 0 +An hourglass in A is a subset of values with indices falling in this pattern in arr's graphical representation: + +a b c + d +e f g + +There are 16 hourglasses in . An hourglass sum is the sum of an hourglass' values. Calculate the hourglass sum for every hourglass in arr, then print the maximum hourglass sum. The array will always be 6x6. + +Example + +arr = +-9 -9 -9 1 1 1 + 0 -9 0 4 3 2 +-9 -9 -9 1 2 3 + 0 0 8 6 6 0 + 0 0 0 -2 0 0 + 0 0 1 2 4 0 + +The 16 hourglass sums are: + +-63, -34, -9, 12, +-10, 0, 28, 23, +-27, -11, -2, 10, + 9, 17, 25, 18 +The highest hourglass sum is 28 from the hourglass beginning at row 1, column 2: + +0 4 3 + 1 +8 6 6 +Note: If you have already solved the Java domain's Java 2D Array challenge, you may wish to skip this challenge. + +Function Description: + +Complete the function hourglassSum in the editor below. + +hourglassSum has the following parameter(s): + +int arr[6][6]: an array of integers +Returns + +int: the maximum hourglass sum + +Input Format +Each of the 6 lines of inputs arr[i] contains 6 space-separated integers arr[i][j]. + +Constraints +-9 <= arr[i][j] <= 9 +0 <= i,j <= 5 + +Output Format +Print the largest (maximum) hourglass sum found in arr. \ No newline at end of file diff --git a/Array/Hourglass in Array/Solution.cpp b/Array/Hourglass in Array/Solution.cpp new file mode 100644 index 0000000..9c54bb4 --- /dev/null +++ b/Array/Hourglass in Array/Solution.cpp @@ -0,0 +1,58 @@ +#include + +using namespace std; + +// Complete the hourglassSum function below. +int hourglassSum(vector> arr) { + + int sum[16]={0}; + int a[36]; + static int r=0,x=0; + + for(int i=0;i<6;i++){ + for(int j=0;j<6;j++,r++){ + a[r]=arr[i][j]; + } + } + + + for(int i=0;i<22;i++,x++){ + sum[x]=a[i]+a[i+1]+a[i+2]+a[i+7]+a[i+12]+a[i+13]+a[i+14]; + if(i==3 || i==9 || i==15) + i+=2; + cout << sum[x] << " "; + } + + int large = sum[0]; + + for(int i=1;i<16;i++){ + if(large> arr(6); + for (int i = 0; i < 6; i++) { + arr[i].resize(6); + + for (int j = 0; j < 6; j++) { + cin >> arr[i][j]; + } + + cin.ignore(numeric_limits::max(), '\n'); + } + + int result = hourglassSum(arr); + + fout << result << "\n"; + + fout.close(); + + return 0; +} \ No newline at end of file From 5a3e5a5cb1be8fa9a0659e9546023d145d4c7b92 Mon Sep 17 00:00:00 2001 From: zomsik Date: Tue, 13 Oct 2020 16:26:45 +0200 Subject: [PATCH 100/109] Added a question and answer to convert decimal numbers to binary numbers --- Stack/Binary numbers/Question.txt | 1 + Stack/Binary numbers/solution.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 Stack/Binary numbers/Question.txt create mode 100644 Stack/Binary numbers/solution.cpp diff --git a/Stack/Binary numbers/Question.txt b/Stack/Binary numbers/Question.txt new file mode 100644 index 0000000..d540fa0 --- /dev/null +++ b/Stack/Binary numbers/Question.txt @@ -0,0 +1 @@ +The question is how to make binary numbers using a stack. \ No newline at end of file diff --git a/Stack/Binary numbers/solution.cpp b/Stack/Binary numbers/solution.cpp new file mode 100644 index 0000000..a388706 --- /dev/null +++ b/Stack/Binary numbers/solution.cpp @@ -0,0 +1,27 @@ +#include +#include +using namespace std; +int main() +{ + int a,b,l,c; + stack stos; + cout << "Number to change: "; + cin >> a; + l=a; + + while(a!=0) + { + b=a%2; + a=a/2; + stos.push(b); + } + cout << "Number " << l << " is equal to: "; + while(!stos.empty()) + { + cout << stos.top(); + stos.pop(); + } + cout << " in binary system."; + +return 0; +} From a7c5f9a88365d7814a0d70546fef55fe91a6472b Mon Sep 17 00:00:00 2001 From: Sankalp Varshney <39947156+ITES7321@users.noreply.github.com> Date: Tue, 13 Oct 2020 21:04:02 +0530 Subject: [PATCH 101/109] Add files via upload --- Hourglass in Array/Hourglass in Array.txt | 15 ++++++ Hourglass in Array/Solution.cpp | 58 +++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 Hourglass in Array/Hourglass in Array.txt create mode 100644 Hourglass in Array/Solution.cpp diff --git a/Hourglass in Array/Hourglass in Array.txt b/Hourglass in Array/Hourglass in Array.txt new file mode 100644 index 0000000..7f1f8f8 --- /dev/null +++ b/Hourglass in Array/Hourglass in Array.txt @@ -0,0 +1,15 @@ +Given a 2D Array, arr: + +1 1 1 0 0 0 +0 1 0 0 0 0 +1 1 1 0 0 0 +0 0 0 0 0 0 +0 0 0 0 0 0 +0 0 0 0 0 0 +An hourglass in A is a subset of values with indices falling in this pattern in arr's graphical representation: + +a b c + d +e f g + +There are 16 hourglasses in arr. An hourglass sum is the sum of an hourglass' values. Calculate the hourglass sum for every hourglass in arr, then print the maximum hourglass sum. The array will always be 6x6. \ No newline at end of file diff --git a/Hourglass in Array/Solution.cpp b/Hourglass in Array/Solution.cpp new file mode 100644 index 0000000..c1af692 --- /dev/null +++ b/Hourglass in Array/Solution.cpp @@ -0,0 +1,58 @@ +#include + +using namespace std; + +// Complete the hourglassSum function below. +int hourglassSum(vector> arr) { + + int sum[16]={0}; + int a[36]; + static int r=0,x=0; + + for(int i=0;i<6;i++){ + for(int j=0;j<6;j++,r++){ + a[r]=arr[i][j]; + } + } + + + for(int i=0;i<22;i++,x++){ + sum[x]=a[i]+a[i+1]+a[i+2]+a[i+7]+a[i+12]+a[i+13]+a[i+14]; + if(i==3 || i==9 || i==15) + i+=2; + cout << sum[x] << " "; + } + + int large = sum[0]; + + for(int i=1;i<16;i++){ + if(large> arr(6); + for (int i = 0; i < 6; i++) { + arr[i].resize(6); + + for (int j = 0; j < 6; j++) { + cin >> arr[i][j]; + } + + cin.ignore(numeric_limits::max(), '\n'); + } + + int result = hourglassSum(arr); + + fout << result << "\n"; + + fout.close(); + + return 0; +} \ No newline at end of file From 4489358f2054ad3ec7ef9b33cc26eaecb403033f Mon Sep 17 00:00:00 2001 From: Sankalp Varshney <39947156+ITES7321@users.noreply.github.com> Date: Tue, 13 Oct 2020 21:09:27 +0530 Subject: [PATCH 102/109] Delete Hourglass in Array.txt --- Hourglass in Array/Hourglass in Array.txt | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 Hourglass in Array/Hourglass in Array.txt diff --git a/Hourglass in Array/Hourglass in Array.txt b/Hourglass in Array/Hourglass in Array.txt deleted file mode 100644 index 7f1f8f8..0000000 --- a/Hourglass in Array/Hourglass in Array.txt +++ /dev/null @@ -1,15 +0,0 @@ -Given a 2D Array, arr: - -1 1 1 0 0 0 -0 1 0 0 0 0 -1 1 1 0 0 0 -0 0 0 0 0 0 -0 0 0 0 0 0 -0 0 0 0 0 0 -An hourglass in A is a subset of values with indices falling in this pattern in arr's graphical representation: - -a b c - d -e f g - -There are 16 hourglasses in arr. An hourglass sum is the sum of an hourglass' values. Calculate the hourglass sum for every hourglass in arr, then print the maximum hourglass sum. The array will always be 6x6. \ No newline at end of file From c50e528a58abb242a7d3caf593fb5824c113410d Mon Sep 17 00:00:00 2001 From: Sankalp Varshney <39947156+ITES7321@users.noreply.github.com> Date: Tue, 13 Oct 2020 21:09:49 +0530 Subject: [PATCH 103/109] Delete Solution.cpp --- Hourglass in Array/Solution.cpp | 58 --------------------------------- 1 file changed, 58 deletions(-) delete mode 100644 Hourglass in Array/Solution.cpp diff --git a/Hourglass in Array/Solution.cpp b/Hourglass in Array/Solution.cpp deleted file mode 100644 index c1af692..0000000 --- a/Hourglass in Array/Solution.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include - -using namespace std; - -// Complete the hourglassSum function below. -int hourglassSum(vector> arr) { - - int sum[16]={0}; - int a[36]; - static int r=0,x=0; - - for(int i=0;i<6;i++){ - for(int j=0;j<6;j++,r++){ - a[r]=arr[i][j]; - } - } - - - for(int i=0;i<22;i++,x++){ - sum[x]=a[i]+a[i+1]+a[i+2]+a[i+7]+a[i+12]+a[i+13]+a[i+14]; - if(i==3 || i==9 || i==15) - i+=2; - cout << sum[x] << " "; - } - - int large = sum[0]; - - for(int i=1;i<16;i++){ - if(large> arr(6); - for (int i = 0; i < 6; i++) { - arr[i].resize(6); - - for (int j = 0; j < 6; j++) { - cin >> arr[i][j]; - } - - cin.ignore(numeric_limits::max(), '\n'); - } - - int result = hourglassSum(arr); - - fout << result << "\n"; - - fout.close(); - - return 0; -} \ No newline at end of file From 2d1f4d2835675a4ba52606a4ab20b1487f23f8ca Mon Sep 17 00:00:00 2001 From: shagunarora Date: Tue, 13 Oct 2020 22:01:31 +0530 Subject: [PATCH 104/109] Generate Parenthesis --- .../Generate_Parenthesis.cpp | 31 +++++++++++++++++++ .../Generate_parenthesis/Question.txt | 7 +++++ 2 files changed, 38 insertions(+) create mode 100644 Backtracking/Generate_parenthesis/Generate_Parenthesis.cpp create mode 100644 Backtracking/Generate_parenthesis/Question.txt diff --git a/Backtracking/Generate_parenthesis/Generate_Parenthesis.cpp b/Backtracking/Generate_parenthesis/Generate_Parenthesis.cpp new file mode 100644 index 0000000..0b6a580 --- /dev/null +++ b/Backtracking/Generate_parenthesis/Generate_Parenthesis.cpp @@ -0,0 +1,31 @@ +#include +using namespace std; +void Generate_Parenthesis(int open, int close, vector &ans, string s) +{ + if (close == 0) + { + ans.push_back(s); + return; + } + if (open) + { + string temp = s; + temp += '('; + Generate_Parenthesis(open - 1, close, ans, temp); + } + if (close > open) + { + string temp = s; + temp += ')'; + Generate_Parenthesis(open, close - 1, ans, temp); + } +} +int main() +{ + int n; + cin >> n; + vector ans; + Generate_Parenthesis(n, n, ans, ""); + for (int i = 0; i < ans.size(); i++) + cout << ans[i] << endl; +} \ No newline at end of file diff --git a/Backtracking/Generate_parenthesis/Question.txt b/Backtracking/Generate_parenthesis/Question.txt new file mode 100644 index 0000000..9012c1d --- /dev/null +++ b/Backtracking/Generate_parenthesis/Question.txt @@ -0,0 +1,7 @@ +Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. + +Sample Input +n = 3 + +Sample Output +["((()))","(()())","(())()","()(())","()()()"] \ No newline at end of file From 30966ca85f1097b334a1893ce62fd7884bd8cc00 Mon Sep 17 00:00:00 2001 From: aroradhruv2308 Date: Tue, 13 Oct 2020 22:10:14 +0530 Subject: [PATCH 105/109] Added question-largest_comman_subsequence --- .../largest_comman_subsecuence.cpp | 35 +++++++++++++++++++ .../largest_comman_subsequece/question.txt | 3 ++ 2 files changed, 38 insertions(+) create mode 100644 Dynamic Programming/largest_comman_subsequece/largest_comman_subsecuence.cpp create mode 100644 Dynamic Programming/largest_comman_subsequece/question.txt diff --git a/Dynamic Programming/largest_comman_subsequece/largest_comman_subsecuence.cpp b/Dynamic Programming/largest_comman_subsequece/largest_comman_subsecuence.cpp new file mode 100644 index 0000000..f8996f7 --- /dev/null +++ b/Dynamic Programming/largest_comman_subsequece/largest_comman_subsecuence.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +using namespace std; +int solver(string s1,string s2,vector>&dp,int n,int m) +{ + if(s1.empty()||s2.empty()) + return 0; + if(dp[n][m] >= 0) + return dp[n][m]; + if(s1[0]==s2[0]) + { + int ans = 1 + solver(s1.substr(1),s2.substr(1),dp,n-1,m-1); + dp[n][m] = ans; + return ans; + } + int ans1 = solver(s1,s2.substr(1),dp,n,m-1); + int ans2 = solver(s1.substr(1),s2,dp,n-1,m); + dp[n][m] = max(ans1,ans2); + return max(ans1,ans2); +} +int lcs(string s1, string s2) +{ + int n = s1.length(),m=s2.length(); + vector>dp(n+1,vector(m+1,-1)); + int ans = solver( s1, s2, dp , s1.length(),s2.length()); + return ans; +} + +int main() +{ + string s1, s2; + cin >> s1 >> s2; + cout << lcs(s1, s2); +} diff --git a/Dynamic Programming/largest_comman_subsequece/question.txt b/Dynamic Programming/largest_comman_subsequece/question.txt new file mode 100644 index 0000000..5f6391b --- /dev/null +++ b/Dynamic Programming/largest_comman_subsequece/question.txt @@ -0,0 +1,3 @@ +LCS Problem Statement: Given two sequences, find the length of longest subsequence present in both of them. A subsequence is a sequence that appears in the same relative order, but not necessarily contiguous. + + From 564bbefa9a282dda6f0bfe43eab01ce733bdf26a Mon Sep 17 00:00:00 2001 From: aakankshaa23 Date: Wed, 14 Oct 2020 12:58:34 +0530 Subject: [PATCH 106/109] added gold mine problem --- .../Gold mine problem/GoldMineProblem.txt | 7 +++ .../Gold mine problem/solution.cpp.txt | 61 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 Dynamic Programming/Gold mine problem/GoldMineProblem.txt create mode 100644 Dynamic Programming/Gold mine problem/solution.cpp.txt diff --git a/Dynamic Programming/Gold mine problem/GoldMineProblem.txt b/Dynamic Programming/Gold mine problem/GoldMineProblem.txt new file mode 100644 index 0000000..76506c3 --- /dev/null +++ b/Dynamic Programming/Gold mine problem/GoldMineProblem.txt @@ -0,0 +1,7 @@ +Gold Mine Problem + +Given a gold mine of n*m dimensions. + Each field in this mine contains a positive integer which is the amount of gold in tons. +Initially the miner is at first column but can be at any row. + He can move only (right->,right up /,right down\) that is from a given cell, the miner can move to the cell diagonally up towards the right or right or diagonally down towards the right. +Find out maximum amount of gold he can collect. \ No newline at end of file diff --git a/Dynamic Programming/Gold mine problem/solution.cpp.txt b/Dynamic Programming/Gold mine problem/solution.cpp.txt new file mode 100644 index 0000000..13394ba --- /dev/null +++ b/Dynamic Programming/Gold mine problem/solution.cpp.txt @@ -0,0 +1,61 @@ +// C++ program to solve Gold Mine problem +#include +using namespace std; + +const int MAX = 100; + +// Returns maximum amount of gold that can be collected +// when journey started from first column and moves +// allowed are right, right-up and right-down +int getMaxGold(int gold[][MAX], int m, int n) +{ + // Create a table for storing intermediate results + // and initialize all cells to 0. The first row of + // goldMineTable gives the maximum gold that the miner + // can collect when starts that row + int goldTable[m][n]; + memset(goldTable, 0, sizeof(goldTable)); + + for (int col=n-1; col>=0; col--) + { + for (int row=0; row) + int right = (col==n-1)? 0: goldTable[row][col+1]; + + // Gold collected on going to the cell to right up (/) + int right_up = (row==0 || col==n-1)? 0: + goldTable[row-1][col+1]; + + // Gold collected on going to the cell to right down (\) + int right_down = (row==m-1 || col==n-1)? 0: + goldTable[row+1][col+1]; + + // Max gold collected from taking either of the + // above 3 paths + goldTable[row][col] = gold[row][col] + + max(right, max(right_up, right_down)); + + } + } + + // The max amount of gold collected will be the max + // value in first column of all rows + int res = goldTable[0][0]; + for (int i=1; i Date: Fri, 23 Oct 2020 10:33:29 +0530 Subject: [PATCH 107/109] Add Rotate the Array Question --- Array/Rotate Array/Question.txt | 1 + Array/Rotate Array/solution.kt | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 Array/Rotate Array/Question.txt create mode 100644 Array/Rotate Array/solution.kt diff --git a/Array/Rotate Array/Question.txt b/Array/Rotate Array/Question.txt new file mode 100644 index 0000000..2152d32 --- /dev/null +++ b/Array/Rotate Array/Question.txt @@ -0,0 +1 @@ +We have to rotate the elements of the given array k times to the right. \ No newline at end of file diff --git a/Array/Rotate Array/solution.kt b/Array/Rotate Array/solution.kt new file mode 100644 index 0000000..0d58479 --- /dev/null +++ b/Array/Rotate Array/solution.kt @@ -0,0 +1,23 @@ +internal class Solution { + fun rotate(nums:IntArray, k:Int) { + k = k % nums.size + val count = 0 + val start = 0 + while (count < nums.size) + { + val current = start + val prev = nums[start] + do + { + val next = (current + k) % nums.size + val temp = nums[next] + nums[next] = prev + prev = temp + current = next + count++ + } + while (start != current) + start++ + } + } +} \ No newline at end of file From bdbcb0d599949557bd88f023a591141c644b5b83 Mon Sep 17 00:00:00 2001 From: poojabasker Date: Fri, 30 Oct 2020 13:14:13 +0530 Subject: [PATCH 108/109] Added Numbers to Words in Basic Math --- .../Number to Words/number_to_words.CPP | 62 +++++++++++++++++++ .../Number to Words/problem_definition.txt | 4 ++ 2 files changed, 66 insertions(+) create mode 100644 Basic Math/Number to Words/number_to_words.CPP create mode 100644 Basic Math/Number to Words/problem_definition.txt diff --git a/Basic Math/Number to Words/number_to_words.CPP b/Basic Math/Number to Words/number_to_words.CPP new file mode 100644 index 0000000..94e3047 --- /dev/null +++ b/Basic Math/Number to Words/number_to_words.CPP @@ -0,0 +1,62 @@ +//Converts any number between 0-9999 (inclusive) to words +//till 4 digits only + +#include +#include + +void words(int n, int c, int r) +{ + if(n==0 && c==1) + { + cout<<"Zero"<=20 || n==10) + { + cout<<" "<=14) + cout<<" "<>n; + int n1=n; + int count=0, rev=0; + while(n1!=0) + { + rev=rev*10+(n1%10); + count++; + n1=n1/10; + } + words(n,count,rev); + getch(); +} \ No newline at end of file diff --git a/Basic Math/Number to Words/problem_definition.txt b/Basic Math/Number to Words/problem_definition.txt new file mode 100644 index 0000000..0e39580 --- /dev/null +++ b/Basic Math/Number to Words/problem_definition.txt @@ -0,0 +1,4 @@ +Write code to convert a given number into words. +For example, +if “1234” is given as input +output should be “one thousand two hundred thirty four”. \ No newline at end of file From 77a9cd899b2630139afcd4beebce0dbf35c0c156 Mon Sep 17 00:00:00 2001 From: SimonLariz <50644041+SimonLariz@users.noreply.github.com> Date: Sat, 31 Oct 2020 09:23:45 -0700 Subject: [PATCH 109/109] Codeforces Problem Addition Addition of A.Team problem from codeforces --- Basic Program/A. Team/A.Team.cpp | 24 ++++++++++++++++++++++ Basic Program/A. Team/A.Team.txt | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 Basic Program/A. Team/A.Team.cpp create mode 100644 Basic Program/A. Team/A.Team.txt diff --git a/Basic Program/A. Team/A.Team.cpp b/Basic Program/A. Team/A.Team.cpp new file mode 100644 index 0000000..05dfbeb --- /dev/null +++ b/Basic Program/A. Team/A.Team.cpp @@ -0,0 +1,24 @@ +#include + +int main() +{ + //Creation of vars + int n, a, b, c, count = 0; + //Take in input for n lines + std::cin >> n; + //Loop for n + for (int i = 0; i < n; i++) + { + //Take in user input + std::cin >> a; + std::cin >> b; + std::cin >> c; + //If more than 2 are sure then they will do the problem + if (a + b + c >= 2) + //Increase problem count + count++; + } + //Return problem count + std::cout << count; + return 0; +} diff --git a/Basic Program/A. Team/A.Team.txt b/Basic Program/A. Team/A.Team.txt new file mode 100644 index 0000000..f7d38b4 --- /dev/null +++ b/Basic Program/A. Team/A.Team.txt @@ -0,0 +1,34 @@ +A. Team [https://codeforces.com/contest/231/problem/A] + + +One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution. + +This contest offers n problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution. + +Input +The first input line contains a single integer n (1 ≤ n ≤ 1000) — the number of problems in the contest. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces. + +Output +Print a single integer — the number of problems the friends will implement on the contest. + +Examples +INPUT +3 +1 1 0 +1 1 1 +1 0 0 +OUTPUT +2 + +INPUT +2 +1 0 0 +0 1 1 +OUTPUT +1 + +Note +In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. + +In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution. +