Super Ugly Number – Extension of Ugly Number Problem

Problem: The problem is an extension of Ugly number problem. Problem Link : Here [Courtesy geeksforgeeks] #include <stdio.h> #include <iostream> using namespace std; int _min(int arr[],int k) { int m= arr[0]; for(int i=1;i<k;i++) { if(m>arr[i]) m=arr[i]; } return m; } int SuperUgly(int n,int k,int primes[]) { int min_val; int superUgly[n]; int tmp[k]; int prime_iterator_count[k]; for(int

Ugly Number Problem

Problem: The problem of ugly number is a common DP problem. Description: Ugly numbers are positive numbers whose prime factors only include 2,3,5,7. For example, 6,8 are ugly while 14 is not ugly since it includes another prime factor 7.Note that 1 is typically treated as an ugly number. courtesy: leetcode.com #include <stdio.h> #include <iostream> using

Number that are not divisible [Paytm]

Problem: Find the number of non-divisible numbers in a range starting from 1 to N, for a given set. Problem Link [Courtesy: geeksforgeeks.org] Appeared as interview question in Paytm. Solution: The given set is {2,3,4,5,6,7,8,9,10}. The set can be minimized to {2,3,5,7} as these are the prime numbers and rest of the numbers of the

661

#include <iostream> #include <cstdio> #include <cstring> #include <string> using namespace std; int capacity[21]; bool isTurnOn[21]; int main() { int n,m,c; int MX=0; int device; int kase=1; bool IsFUSE; long long total; while(scanf("%d%d%d",&n,&m,&c)) { if(n+m+c==0) break; //memset(capacity,0,sizeof(capacity)); //memset(isTurnOn,0,sizeof(isTurnOn)); IsFUSE=0; for(int i=1;i<=n;i++) { scanf("%d",&capacity[i]); isTurnOn[i]=0; } total=0; MX=0; for(int i=1;i<=m;i++) { scanf("%d",&device); if(IsFUSE) continue; if(isTurnOn[device]==0) { isTurnOn[device]=1;

10102

Critical t get the question but easy to solve. Problem asks to find the maximum length of minimum distance. #include <iostream> #include <cstdio> #include <vector> #include <stack> #include <cmath> #include <cstring> #include <fstream> #include <string> #include <algorithm> #define INF 100000000 #define ll long long using namespace std; struct Cord{ int x,y; }; int M; char

11661

#include <iostream> #include <cstdio> #include <sstream> #include <string> #include <cstring> using namespace std; char s[2000000+10]; int main() { int n,dist,prev_idx; char prev; bool first; while(scanf("%d",&n),n) { dist= n; first=0; scanf("%s",s); for(int i=0;i<n;i++) { //scanf("%c",&s[i]); if(s[i]=='Z') dist=0; if(s[i]=='R' && first==false) { prev='R'; prev_idx=i; first=true; continue; } if(s[i]=='D' && first==false) { prev='D'; prev_idx=i; first=true; continue; } if(first==1

11734

#include <cstdio> #include <vector> #include <cstring> #include <algorithm> #include <iostream> using namespace std; int main() { int t,kase=1; string org,ans,tmp1,tmp2; scanf("%d",&t); getchar(); while(t–) { getline(cin,ans); getline(cin,org); if(org.size()==ans.size()) { bool f=0; for(int i=0;i<org.size();i++) { if(org[i]!=ans[i]) { f=1;break; } } if(f) printf("Case %d: Wrong Answer\n",kase++); else printf("Case %d: Yes\n",kase++); } else { tmp1="";tmp2=""; for(int i=0;i<org.size();i++) { if(org[i]!='

11936

#include <iostream> #include <cstdio> #include <sstream> #include <string> using namespace std; int main() { int n,a,b,c; scanf("%d",&n); while(n–) { scanf("%d%d%d",&a,&b,&c); bool OK=1; if(a>=(b+c)) OK=0; if(b>=(a+c)) OK=0; if(c>=(a+b)) OK=0; if(OK) printf("OK\n"); else printf("Wrong!!\n"); } return 0; }  

12136

#include <iostream> #include <cstdio> #include <queue> #include <sstream> #include <string> #include <cstring> #include <cmath> using namespace std; int main() { int t; int kase=1; int hr1,hr2,hr3,hr4; int t1,t2,t3,t4; int mn1,mn2,mn3,mn4; string str1,str2,str3,str4; scanf("%d",&t); while(t–) { cin>>str1>>str2; cin>>str3>>str4; hr1=hr2=hr3=hr4=0; mn1=mn2=mn3=mn4=0; hr1=str1[0]-'0';hr1*=10; hr1+=(str1[1]-'0'); hr2=str2[0]-'0';hr2*=10; hr2+=(str2[1]-'0'); hr3=str3[0]-'0';hr3*=10; hr3+=(str3[1]-'0'); hr4=str4[0]-'0';hr4*=10; hr4+=(str4[1]-'0'); mn1=str1[3]-'0';mn1*=10; mn1+=(str1[4]-'0'); mn2=str2[3]-'0';mn2*=10; mn2+=(str2[4]-'0'); mn3=str3[3]-'0';mn3*=10; mn3+=(str3[4]-'0'); mn4=str4[3]-'0';mn4*=10; mn4+=(str4[4]-'0');

12468

#include <iostream> #include <cstdio> #include <cstdio> #include <cstring> #include <vector> #include <cmath> #include <cstdlib> #define INF 1000000 #define ll long long using namespace std; int main() { int m,n,diff1,diff2; while(scanf("%d%d",&m,&n) && m!=-1 && n!=-1) { if(m==-1 && n==-1) break; diff1 = abs(m-n); if(diff1<=50) printf("%d\n",diff1); else printf("%d\n",100-diff1); } return 0; }