Skip to content

Instantly share code, notes, and snippets.

View AashishNandakumar's full-sized avatar
:shipit:
Developing...

Aashish Nandakumar AashishNandakumar

:shipit:
Developing...
View GitHub Profile
@AashishNandakumar
AashishNandakumar / 1143_Queens.py
Last active September 9, 2024 10:38
September 9th 2024 Questions
n = int(input())
respect = [1] * (n + 1)
for i in range(1, n + 1):
p, c = map(int, input().split())
if not c:
respect[i] = respect[p] = 0
res = set(i for i in range(1, n + 1) if respect[i])
@AashishNandakumar
AashishNandakumar / 1845_forbidden_integer.py
Last active September 6, 2024 09:07
September 6th 2024 Questions
def forbidden_integer():
n, k, x = map(int, input().split())
if x != 1:
# We can always form n using 1's
print("YES")
print(n)
print(" ".join(["1"] * n))
elif n > 1 and k > 1:
# We can for n using 2's and possibly one 3
@AashishNandakumar
AashishNandakumar / 1055_metro.py
Created September 4, 2024 17:31
September 4th 2024 Questions
# input
n, s = map(int, input().split())
a = [0] + list(map(int, input().split())) + [0]
b = [0] + list(map(int, input().split())) + [0]
# logic
reachable = False
for i in range(1, n + 1):
if i == 1 and a[i] == 0:
print("NO")
@AashishNandakumar
AashishNandakumar / 1472_long_jumps_brute_force.py
Last active September 4, 2024 12:40
September 3rd 2024 questions
def long_jumps():
# input
n = int(input())
a = list(map(int, input().split()))
# logic
globalMaxScore = float("-inf")
ptr = 0
while ptr < n:
@AashishNandakumar
AashishNandakumar / 1858_buttons.py
Created September 2, 2024 09:53
September 2nd 2024 Questions
def buttons():
a, b, c = map(int, input().split())
if c % 2 == 0:
if b >= a:
return "Second"
return "First"
else:
if a >= b:
return "First"
return "Second"
@AashishNandakumar
AashishNandakumar / 1251_average_selling_price.sql
Created September 1, 2024 08:10
September 1st 2024 Questions
# Write your MySQL query statement below
select p.product_id, ifnull(round(sum(p.price * u.units) / sum(u.units), 2), 0) as average_price
from Prices p left join UnitsSold u on p.product_id=u.product_id and u.purchase_date between p.start_date and p.end_date
group by p.product_id;
@AashishNandakumar
AashishNandakumar / 1862_sequence_game.py
Last active August 31, 2024 16:54
August 31st 2024 Questions
def sequence_game():
n = int(input())
b = list(map(int, input().split()))
res = [b[0]]
for i in range(1, n):
if b[i] < b[i - 1]:
res.append(1)
res.append(b[i])
@AashishNandakumar
AashishNandakumar / 1873_target_practice.py
Last active August 30, 2024 05:58
August 30th 2024 Questions
def target_practice():
# hardcode the target matrix since it is always 10 * 10 matrix with fixed values
target = [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 2, 2, 2, 2, 2, 2, 2, 2, 1],
[1, 2, 3, 3, 3, 3, 3, 3, 2, 1],
[1, 2, 3, 4, 4, 4, 4, 3, 2, 1],
[1, 2, 3, 4, 5, 5, 4, 3, 2, 1],
[1, 2, 3, 4, 5, 5, 4, 3, 2, 1],
[1, 2, 3, 4, 4, 4, 4, 3, 2, 1],
class Solution:
#User function Template for python3
#Complete this function
def findFloor(self,A,N,X):
#Your code here
nums = A
x = X
n = N
int go(int[] a, int l, int r) {
if (l == r)
return a[l];
int mid = (l + r) / 2;
return go(a, l, mid) + go(a, mid + 1, r);
}
int[] a = {...};
int N = a.length;