Skip to content

Commit a536903

Browse files
committed
new Codesignals problems
1 parent 388e742 commit a536903

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+254
-0
lines changed

CodeChef/BinAddC.cpp

100644100755
File mode changed.

CodeChef/CKWLK.cpp

100644100755
File mode changed.

CodeChef/COIN.cpp

100644100755
File mode changed.

CodeChef/COOK13B/CHANGT.cpp

100644100755
File mode changed.

CodeChef/COOK13B/PRFYIT.cpp

100644100755
File mode changed.

CodeChef/Chef&Sorting.cpp

100644100755
File mode changed.

CodeChef/FEB20B/cash.cpp

100644100755
File mode changed.

CodeChef/FEB20B/cpptry.cpp

100644100755
File mode changed.

CodeChef/FEB20B/input.txt

100644100755
File mode changed.

CodeChef/FEB20B/nochange.cpp

100644100755
File mode changed.

CodeChef/FEB20B/output.txt

100644100755
File mode changed.

CodeChef/FEB20B/snug_fit.cpp

100644100755
File mode changed.

CodeChef/FEB20B/theater.cpp

100644100755
File mode changed.

CodeChef/JAN20B/CHEFDORA.cpp

100644100755
File mode changed.

CodeChef/JAN20B/ISBIS.cpp

100644100755
File mode changed.

CodeChef/JAN20B/dynamo.cpp

100644100755
File mode changed.

CodeChef/LinkedList.cpp

100644100755
File mode changed.

CodeChef/MARAM.cpp

100644100755
File mode changed.

CodeChef/MDL.cpp

100644100755
File mode changed.

CodeChef/MSVPract.cpp

100644100755
File mode changed.

CodeChef/NPLQ.cpp

100644100755
File mode changed.

CodeChef/PLMU.cpp

100644100755
File mode changed.

CodeChef/PRIME1.cpp

100644100755
File mode changed.

CodeChef/SIMgam.cpp

100644100755
File mode changed.

CodeChef/SKTAN.cpp

100644100755
File mode changed.

CodeChef/WATSCORE.cpp

100644100755
File mode changed.

CodeChef/ch1.cpp

100644100755
File mode changed.

CodeChef/hrsDQtry.cpp

100644100755
File mode changed.

CodeChef/suborg.cpp

100644100755
File mode changed.

CodeForces/R629 Div 3/A

15.4 KB
Binary file not shown.

CodeForces/R629 Div 3/A.cpp

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
#include <bits/stdc++.h>
3+
#include <cstdio>
4+
#include <cstring>
5+
#include <cmath>
6+
#include <cstring>
7+
#include <chrono>
8+
#include <complex>
9+
#define endl "\n"
10+
#define ll long long int
11+
#define vi vector<int>
12+
#define vll vector<ll>
13+
#define vvi vector < vi >
14+
#define pii pair<int,int>
15+
#define pll pair<long long, long long>
16+
#define mod 1000000007
17+
#define inf 1000000000000000001;
18+
#define all(c) c.begin(),c.end()
19+
#define mp(x,y) make_pair(x,y)
20+
#define mem(a,val) memset(a,val,sizeof(a))
21+
#define eb emplace_back
22+
#define f first
23+
#define s second
24+
25+
using namespace std;
26+
int main()
27+
{
28+
std::ios::sync_with_stdio(false);
29+
int T;
30+
cin>>T;
31+
// cin.ignore(); must be there when using getline(cin, s)
32+
while(T--)
33+
{
34+
int a, b;
35+
cin>>a>>b;
36+
37+
int ans = b - (a%b);
38+
if(ans!=b)
39+
cout<<ans<<endl;
40+
else
41+
cout<<0<<endl;
42+
}
43+
return 0;
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/*Please add ; after each select statement*/
2+
CREATE PROCEDURE countriesSelection()
3+
BEGIN
4+
select name, continent, population from countries where continent='Africa';
5+
END
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/*Please add ; after each select statement*/
2+
CREATE PROCEDURE monthlyScholarships()
3+
BEGIN
4+
select id, scholarship/12 "scholarship" from scholarships;
5+
END

CodeSignal/Edge of the ocean/ShapeArea.cpp

100644100755
File mode changed.

CodeSignal/Edge of the ocean/adjecentElementProduct.cpp

100644100755
File mode changed.

CodeSignal/Edge of the ocean/almostIncreasingSequence.cpp

100644100755
File mode changed.

CodeSignal/Edge of the ocean/makeArrayConsecutive2.cpp

100644100755
File mode changed.

CodeSignal/Edge of the ocean/matrixElementSum.cpp

100644100755
File mode changed.

CodeSignal/InteviewQuestions/firstDuplicate.cpp

100644100755
File mode changed.

CodeSignal/InteviewQuestions/missingNumber.cpp

100644100755
File mode changed.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//top Solution
2+
int commonCharacterCount(std::string s1, std::string s2) {
3+
int count1[26] = {0};
4+
int count2[26] = {0};
5+
6+
for(char c: s1) ++count1[c-'a'];
7+
for(char c: s2) ++count2[c-'a'];
8+
9+
int ret = 0;
10+
for(int i=0; i<26; ++i)
11+
ret += min(count1[i],count2[i]);
12+
13+
return ret;
14+
}
15+
16+
17+
//My
18+
19+
int commonCharacterCount(std::string s1, std::string s2) {
20+
int res = 0;
21+
22+
for(int i = 0; i < s1.length(); i++){
23+
for(int j = 0; j < s2.length(); j++){
24+
if(s1[i] == s2[j]){
25+
res++;
26+
s2[j] = ' ';
27+
break;
28+
}
29+
}
30+
}
31+
return res;
32+
33+
}
34+
35+
//with map
36+
int commonCharacterCount(std::string s1, std::string s2) {
37+
map<int,int> resultTable1;
38+
map<int,int> resultTable2;
39+
int sum = 0;
40+
41+
for(int i=0;i<s1.size();i++){
42+
resultTable1[s1.at(i)]++;
43+
}
44+
for(int i=0;i<s2.size();i++){
45+
resultTable2[s2.at(i)]++;
46+
}
47+
48+
for(int i='a';i<='z';i++){
49+
sum += min(resultTable1[i],resultTable2[i]);
50+
}
51+
52+
return sum;

CodeSignal/SmoothSailing/firstDuplicate.cpp

100644100755
File mode changed.
35 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include<bits/stdc++.h>
2+
#include<string.h>
3+
using namespace std;
4+
5+
6+
7+
string revS(string s){
8+
string s1;
9+
stack<char> stk;
10+
for(int i = 0; i < s.length(); i++){
11+
if(s[i] == '('){
12+
while(s[i] != ')'){
13+
if(s[++i] == '('){
14+
15+
while(s[i] != ')')
16+
s1.push_back(s[i]);
17+
}
18+
stk.push(s[++i]);
19+
}
20+
while(!stk.empty()){
21+
if(stk.top() != ')' && stk.top() != '(')
22+
s1.push_back(stk.top());
23+
stk.pop();
24+
}
25+
}
26+
27+
if(s[i] != '(' && s[i] != ')')
28+
s1.push_back(s[i]);
29+
}
30+
31+
return s1;
32+
33+
}
34+
35+
int main(int argc, char const *argv[])
36+
{
37+
string s = "foo(bar(baz))blim";
38+
39+
string ans = "foobazrabblim";
40+
s = revS(s);
41+
if(s == ans)
42+
cout<<1;
43+
else{
44+
cout<<0<<endl;
45+
cout<<s;
46+
}
47+
48+
49+
return 0;
50+
}
51+
52+
string reverseInParentheses(string s) {
53+
int a,b;
54+
for(int i = 0; i < s.size(); i++){
55+
if(s[i] == '(')
56+
a = i;
57+
if(s[i] == ')')
58+
{
59+
b = i;
60+
string t = s.substr(a + 1, b - a - 1);
61+
reverse(t.begin(), t.end());
62+
return reverseInParentheses(s.substr(0, a) + t + s.substr(b + 1));
63+
}
64+
}
65+
return s;
66+
}
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//top solution
2+
std::vector<int> t, sortByHeight(std::vector<int> a) {
3+
for (x:a) if (x>-1) t.push_back(x);
4+
sort(begin(t), end(t));
5+
auto p = begin(t);
6+
for (x:a) if (x>-1) x = *(p++);
7+
return a;
8+
}
9+
10+
//my
11+
std::vector<int> sortByHeight(std::vector<int> a) {
12+
for(int i = 0; i < a.size()-1; i++){
13+
if(a[i] == -1)
14+
continue;
15+
int min = i;
16+
17+
for(int j = i+1; j < a.size(); j++){
18+
if(a[j] == -1)
19+
continue;
20+
21+
if(a[min] > a[j])
22+
min = j;
23+
}
24+
int temp = a[i];
25+
a[i] = a[min];
26+
a[min] = temp;
27+
28+
}
29+
30+
return a;

CodeSignal/The Journey Begins/add.cpp

100644100755
File mode changed.

CodeSignal/The Journey Begins/centuryFromYear.cpp

100644100755
File mode changed.

CodeSignal/The Journey Begins/checkPalindrome.cpp

100644100755
File mode changed.

CodeWarsSolutions/Equal.js

100644100755
File mode changed.

CodeWarsSolutions/JadenCapital.js

100644100755
File mode changed.

CodeWarsSolutions/PhoneNumber.js

100644100755
File mode changed.

CodeWarsSolutions/iqTEST.js

100644100755
File mode changed.

Language/Java/Book.class

100644100755
File mode changed.

Language/Java/Employee.class

100644100755
File mode changed.

Language/Java/Exp2.class

100644100755
File mode changed.

Language/Java/Exp2.java

100644100755
File mode changed.

Language/Java/FileOp.class

100644100755
File mode changed.

Language/Java/FileOp.java

100644100755
File mode changed.

Language/Java/Sample.class

100644100755
File mode changed.

Language/Java/file.txt

100644100755
File mode changed.

Language/Java/output.ser

100644100755
File mode changed.

Language/Java/tryColl.class

100644100755
File mode changed.

Language/Java/tryColl.java

100644100755
File mode changed.

Language/Java/tryHash.class

100644100755
File mode changed.

Language/Java/tryHash.java

100644100755
File mode changed.

Language/OS/os1.c

100644100755
File mode changed.

README.md

100644100755
File mode changed.

binsearch.cpp

100644100755
File mode changed.

ccTemplate.cpp

100644100755
File mode changed.

isLucky

24.5 KB
Binary file not shown.

isLucky.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//top solution
2+
bool isLucky(int n) {
3+
int digits = (int)log10(n) + 1;
4+
int sum1 = 0, sum2 = 0;
5+
6+
7+
for (int x = 0; n > 0; n /= 10, x++) {
8+
if (x < digits / 2)
9+
sum1 += n % 10;
10+
else
11+
sum2 += n % 10;
12+
}
13+
14+
return sum1 == sum2;
15+
}
16+
17+
//my sol
18+
bool isLucky(int n) {
19+
vector<int> v;
20+
while(n>0){
21+
v.push_back(n%10);
22+
n = n/10;
23+
}
24+
int f_half=0, s_half=0, half = v.size()/2;
25+
26+
27+
for (int i = 0; i < half; i++)
28+
f_half += v[i];
29+
30+
for(int i = half; i < v.size(); i++)
31+
s_half += v[i];
32+
33+
//cout<<f_half<<s_half;
34+
return(f_half == s_half);
35+
36+
37+
}
38+
39+

leetcode/PalNumE.cpp

100644100755
File mode changed.

leetcode/RevIntE.cpp

100644100755
File mode changed.

leetcode/addtwoAvg.cpp

100644100755
File mode changed.

leetcode/twoSum.cpp

100644100755
File mode changed.

testPrg

8.52 KB
Binary file not shown.

testPrg.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main(){
5+
6+
int val =0;
7+
std::cout<<val;
8+
}
9+
10+
unsigned GetNumberOfDigits (unsigned i)
11+
{
12+
return i > 0 ? (int) log10 ((double) i) + 1 : 1;
13+
}

0 commit comments

Comments
 (0)