Skip to content

Commit 3aba03d

Browse files
committed
Solving more arcade the core, challenges and interview problems
1 parent f71566f commit 3aba03d

File tree

10 files changed

+121
-0
lines changed

10 files changed

+121
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
int addTwoDigits(int n)
2+
{
3+
string myNumb = n.ToString();
4+
string firstDigit = myNumb.Substring(0, 1);
5+
string secondDigit = myNumb.Substring(1, 1);
6+
int fd = Int32.Parse(firstDigit);
7+
int sd = Int32.Parse(secondDigit);
8+
return fd + sd;
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
int largestNumber(int n)
2+
{
3+
int num = 10;
4+
for (int i = 1; i < n; i++)
5+
{
6+
num = num * 10;
7+
}
8+
9+
return num - 1;
10+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def candies(n, m)
2+
num = 0
3+
newNum = 0
4+
i = 0
5+
while newNum < m do
6+
num = newNum
7+
newNum = n * i
8+
i += 1
9+
end
10+
if newNum == m
11+
return newNum
12+
else
13+
return num
14+
end
15+
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
int seatsInTheater(int nCols, int nRows, int col, int row)
2+
{
3+
return (nCols - col + 1) * (nRows - row);
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
int maxMultiple(int divisor, int bound)
2+
{
3+
int n = bound;
4+
while (n % divisor != 0) n--;
5+
return n;
6+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
int circleOfNumbers(int n, int firstNumber)
2+
{
3+
if (n % 2 != 0) return ((n - 1) / 2 + firstNumber) % n;
4+
else return (n / 2 + firstNumber) % n;
5+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
int lateRide(int n)
2+
{
3+
std::string hours = std::to_string(n / 60);
4+
std::string minutes = std::to_string(n % 60);
5+
6+
int sum = 0;
7+
8+
if (hours.length() == 1) sum = sum + std::stoi(hours.substr(0, 1));
9+
else
10+
{
11+
sum = sum + std::stoi(hours.substr(0, 1));
12+
sum = sum + std::stoi(hours.substr(1, 1));
13+
}
14+
15+
if (minutes.length() == 1) sum = sum + std::stoi(minutes.substr(0, 1));
16+
else
17+
{
18+
sum = sum + std::stoi(minutes.substr(0, 1));
19+
sum = sum + std::stoi(minutes.substr(1, 1));
20+
}
21+
22+
return sum;
23+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
int phoneCall(int min1, int min2_10, int min11, int s)
2+
{
3+
int minutes = 0;
4+
if (s < min1)
5+
{
6+
return 0;
7+
}
8+
else
9+
{
10+
minutes++;
11+
s = s - min1;
12+
}
13+
14+
if (s < min2_10)
15+
{
16+
return minutes;
17+
}
18+
else if (s >= min2_10 && s <= min2_10 * 9)
19+
{
20+
minutes = minutes + s / min2_10;
21+
s = s - (s / min2_10) * min2_10;
22+
}
23+
else
24+
{
25+
minutes = minutes + 9;
26+
s = s - 9 * min2_10;
27+
28+
minutes = minutes + s / min11;
29+
s = s - (s / min11) * min11;
30+
}
31+
return minutes;
32+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
boolean isoscelesTriangle(int[] sides)
2+
{
3+
int a = sides[0];
4+
int b = sides[1];
5+
int c = sides[2];
6+
7+
/*if (a + b <= c || a + c <= b || b + c <= a || a <= 0 || b <= 0 || c <= 0) return false;
8+
else */if (a == b || a == c || b == c) return true;
9+
else return false;
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
def firstDuplicate(a):
2+
aSet = set()
3+
for i in a:
4+
if i in aSet:
5+
return i
6+
aSet.add(i)
7+
return -1

0 commit comments

Comments
 (0)