Check this website to practice for the INSA test. There are some rumors that INSA takes questions from this site.
Mensa IQ Test
Leetcode with dani
I'll share any new info as soon as I get it!
Mensa IQ Test
Leetcode with dani
I'll share any new info as soon as I get it!
π4β1
can u solve this question? the logic is simple but it may take while to figure it out
70. Climbing Stairs
Solved
Easy
You are climbing a staircase. It takes n steps to reach the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
Example 1:
Input: n = 2
Output: 2
Explanation: There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps
Example 2:
Input: n = 3
Output: 3
Explanation: There are three ways to climb to the top.
1. 1 step + 1 step + 1 step
2. 1 step + 2 steps
3. 2 steps + 1 step
Constraints:
1 <= n <= 45
see the question in leetcode
70. Climbing Stairs
Solved
Easy
You are climbing a staircase. It takes n steps to reach the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
Example 1:
Input: n = 2
Output: 2
Explanation: There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps
Example 2:
Input: n = 3
Output: 3
Explanation: There are three ways to climb to the top.
1. 1 step + 1 step + 1 step
2. 1 step + 2 steps
3. 2 steps + 1 step
Constraints:
1 <= n <= 45
see the question in leetcode
Leetcode with dani
can u solve this question? the logic is simple but it may take while to figure it out 70. Climbing Stairs Solved Easy You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct waysβ¦
What if the question asks to use 1,2 and 3 steps?
Leetcode with dani
can u solve this question? the logic is simple but it may take while to figure it out 70. Climbing Stairs Solved Easy You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct waysβ¦
a, b= 1, 2
for i in range(3,n+1):
a, b = b, a + b
return b
π5π€―1
Leetcode with dani
What if the question asks to use 1,2 and 3 steps?
a, b, c = 1, 2, 4
for i in range(4, n+1):
a, b, c = b, c, a + b + c
return c
Hey Developers! Let me introduce you to an amazing project: an unlimited free phone verification API created by my friend Yonatan. Check it out!
Forwarded from Yonathan
Built something cool! π
Verify is my personal projectβan API for free, unlimited phone verification using Telegram. No SMS costs, simple integration, and optional self-hosting.
π Check it out: https://verify.yonathan.tech
Would love your feedback!
Verify is my personal projectβan API for free, unlimited phone verification using Telegram. No SMS costs, simple integration, and optional self-hosting.
π Check it out: https://verify.yonathan.tech
Would love your feedback!
i want to make this channel more usefull for u so .what type of post do u want to see more often?
Anonymous Poll
23%
tech news
54%
algorithm explanation with question
33%
more questions with similar pattern
25%
get matched with other memebers to do mock interviews
25%
just to see the result
if u have better ideas, i would love to hear and collaborate with u .please feel free to contact me with this bot @zprogramming_bot
here is the first question of A2SV weekly contest For G6 i will post each question with their answer
βπ A. Pens and Pencils
βProblem Statement
Tomorrow is a difficult day for Polycarp: he has to attend lectures and practical classes at the university! He writes lectures with pens and practicals with pencils.
β’ One pen lasts for
β’ One pencil lasts for
β’ His pencil case can hold at most
Can Polycarp pack enough pens and pencils to cover the day?
---
βInput Format
β’ First line: An integer
β’ Each test case: Five integers
β
β
β
β
β
---
βOutput Format
For each test case, output:
β’ Two integers
β
β
β’ Or output
---
βExample Input
βExample Output
---
βExplanation
β’ Test Case 1:
β Needs
β Total =
β’ Test Case 2:
β Needs
β Total =
β’ Test Case 3:
β Needs
β Total =
---
βSample Code (Python)
βπ A. Pens and Pencils
βProblem Statement
Tomorrow is a difficult day for Polycarp: he has to attend lectures and practical classes at the university! He writes lectures with pens and practicals with pencils.
β’ One pen lasts for
c lectures.β’ One pencil lasts for
d practicals.β’ His pencil case can hold at most
k writing tools in total.Can Polycarp pack enough pens and pencils to cover the day?
---
βInput Format
β’ First line: An integer
t (1 β€ t β€ 100), the number of test cases.β’ Each test case: Five integers
a, b, c, d, kβ
a: Number of lecturesβ
b: Number of practical classesβ
c: Lectures per penβ
d: Practicals per pencilβ
k: Maximum tools in the pencil case---
βOutput Format
For each test case, output:
β’ Two integers
x y, where:β
x: Number of pensβ
y: Number of pencilsβ’ Or output
-1 if itβs not possible to pack enough tools.---
βExample Input
3
7 5 4 5 8
7 5 4 5 2
20 53 45 26 4
βExample Output
2 1
-1
1 3
---
βExplanation
β’ Test Case 1:
β Needs
ceil(7/4) = 2 pens and ceil(5/5) = 1 pencil.β Total =
2 + 1 = 3 β€ 8 (possible).β’ Test Case 2:
β Needs
2 pens and 1 pencil.β Total =
2 + 1 = 3 > 2 (not possible).β’ Test Case 3:
β Needs
1 pen (ceil(20/45)) and 3 pencils (ceil(53/26)).β Total =
1 + 3 = 4 = 4 (possible).---
βSample Code (Python)
t = int(input())
for _ in range(t):
a, b, c, d, k = map(int, input().split())
pens_needed = (a + c - 1) // c # Ceiling of a/c
pencils_needed = (b + d - 1) // d # Ceiling of b/d
if pens_needed + pencils_needed <= k:
print(pens_needed, pencils_needed)
else:
print(-1)
β€3
βB. Integer Points
βProblem (brief)
DLS draws
βKey Fact
The intersection of y = x + p and y = -x + q is given by:
For both x and y to be integers, q and p must have the same parity.
βSolution
1. Count the number of even and odd integers in sets P and Q.
2. The total number of intersecting pairs is calculated as:
βImplementation
βExample
βInput
βOutput
βProblem (brief)
DLS draws
n lines of the form y = x + pα΅’ and JLS draws m lines of the form y = -x + qβ±Ό . Count how many pairs (one from each set) intersect at integer coordinates (x, y).βKey Fact
The intersection of y = x + p and y = -x + q is given by:
x = q - p / 2, y = q + p / 2
For both x and y to be integers, q and p must have the same parity.
βSolution
1. Count the number of even and odd integers in sets P and Q.
2. The total number of intersecting pairs is calculated as:
Answer = (even_P Γ even_Q) + (odd_P Γ odd_Q)
βImplementation
for _ in range(int(input())):
n, P = int(input()), list(map(int, input().split()))
m, Q = int(input()), list(map(int, input().split()))
eP = sum(p % 2 == 0 for p in P) # Count evens in P
oP = n - eP # Count odds in P
eQ = sum(q % 2 == 0 for q in Q) # Count evens in Q
oQ = m - eQ # Count odds in Q
print(eP * eQ + oP * oQ)
βExample
βInput
3
3
1 3 2
2
0 3
1
1
1
1
1
2
1
1
βOutput
3
1
0
β€6
βC. Labs (Simplified)
You have nΒ² labs numbered from 1 (lowest) to nΒ² (highest).
Any lab u can send 1 unit of water to any lower lab v if u > v .
βProblem Statement
Split the labs into n groups of size n .
For each ordered pair of groups (A, B) , let f(A, B) be the total units sendable from all labs in A to all in B .
Objective: Maximize the minimum f(A, B) over all A β B .
βOutput
Print any grouping that achieves this.
βExample
Input:
Output (one possible grouping):
Here, n = 3 , meaning there are labs numbered from 1 to 9.
Every group has 3 labs.
The smallest f(A, B) among all 6 ordered pairs is 4, which is optimal.
Solution
You have nΒ² labs numbered from 1 (lowest) to nΒ² (highest).
Any lab u can send 1 unit of water to any lower lab v if u > v .
βProblem Statement
Split the labs into n groups of size n .
For each ordered pair of groups (A, B) , let f(A, B) be the total units sendable from all labs in A to all in B .
Objective: Maximize the minimum f(A, B) over all A β B .
βOutput
Print any grouping that achieves this.
βExample
Input:
3
Output (one possible grouping):
2 8 5
9 3 4
7 6 1
Here, n = 3 , meaning there are labs numbered from 1 to 9.
Every group has 3 labs.
The smallest f(A, B) among all 6 ordered pairs is 4, which is optimal.
Solution
def main():
n = int(input())
groups = [[] for _ in range(n)]
num = 1
for row in range(n):
# decide direction: leftβtoβright on even rows, rightβtoβleft on odd
cols = range(n) if row % 2 == 0 else range(n - 1, -1, -1)
for col in cols:
groups[col].append(num)
num += 1
# output
for g in groups:
print(*g)
if __name__ == "__main__":
main()
β€5
βπ§© D. Add on a Tree (Simplified)
You are given a tree (a connected graph with no cycles) of n nodes. Each edge in the tree initially has a value of 0.
You can perform the following operation:
> Choose any two leaf nodes (nodes connected to only one other node), and a real number x.
> Then, add
π You can repeat this operation as many times as you want, with different pairs of leaves and values.
---
ββ Question
Is it possible to reach any possible configuration of real numbers on the edges using a finite number of such operations?
Print:
β’ YES β if itβs always possible for this tree
β’ NO β if there exists any configuration that you cannot reach
---
βπ₯ Input
β’ First line:
β’ Next
It is guaranteed that the graph is a tree.
---
βπ€ Output
β’ Print YES or NO
---
βπ Examples
Input
Output
You are given a tree (a connected graph with no cycles) of n nodes. Each edge in the tree initially has a value of 0.
You can perform the following operation:
> Choose any two leaf nodes (nodes connected to only one other node), and a real number x.
> Then, add
x to all edges on the simple path between these two leaf nodes.π You can repeat this operation as many times as you want, with different pairs of leaves and values.
---
ββ Question
Is it possible to reach any possible configuration of real numbers on the edges using a finite number of such operations?
Print:
β’ YES β if itβs always possible for this tree
β’ NO β if there exists any configuration that you cannot reach
---
βπ₯ Input
β’ First line:
n β number of nodes (2 β€ n β€ 10β΅)β’ Next
n-1 lines: two integers u and v, meaning an edge between node u and node vIt is guaranteed that the graph is a tree.
---
βπ€ Output
β’ Print YES or NO
---
βπ Examples
Input
2
1 2
Output
YES
Leetcode with dani
βπ§© D. Add on a Tree (Simplified) You are given a tree (a connected graph with no cycles) of n nodes. Each edge in the tree initially has a value of 0. You can perform the following operation: > Choose any two leaf nodes (nodes connected to only one otherβ¦
Answer :
def main():
def iinp(): return (int(input()))
def linp(): return (list(map(int, input().split())))
n = iinp()
arr = [0 for i in range(n+1)]
for i in range(n-1):
u,v = linp()
arr[u] += 1
arr[v] += 1
for i in arr:
if i ==2:
print("NO")
return
print("YES")
main()
E. Nauuo and Cards (Simplified Version)
Nauuo has 2n cards:
n real cards numbered from 1 to n
n empty cards, represented as 0
These cards are randomly shuffled and split into:
Nauuoβs hand β a list of n cards
The pile β another list of n cards, ordered top to bottom
β Operation
She can:
Choose any card from her hand, and
Play it β move it to the bottom of the pile,
Then draw the top card of the pile into her hand.
She wants the pile to end up as [1, 2, 3, ..., n] (from top to bottom) as fast as possible.
Nauuo has 2n cards:
n real cards numbered from 1 to n
n empty cards, represented as 0
These cards are randomly shuffled and split into:
Nauuoβs hand β a list of n cards
The pile β another list of n cards, ordered top to bottom
β Operation
She can:
Choose any card from her hand, and
Play it β move it to the bottom of the pile,
Then draw the top card of the pile into her hand.
She wants the pile to end up as [1, 2, 3, ..., n] (from top to bottom) as fast as possible.
Leetcode with dani
E. Nauuo and Cards (Simplified Version) Nauuo has 2n cards: n real cards numbered from 1 to n n empty cards, represented as 0 These cards are randomly shuffled and split into: Nauuoβs hand β a list of n cards The pile β another list of n cards, orderedβ¦
def main():
n = int(input().strip())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
pos = [0] * (n + 1)
for idx in range(n):
if b[idx]:
pos[b[idx]] = idx + 1
if pos[1] != 0:
i = 2
while i <= n and pos[i] == pos[1] + i - 1:
i += 1
if i - 1 >= 1 and pos[i - 1] == n:
j = i
while j <= n:
if pos[j] != 0 and pos[j] > j - i:
break
j += 1
else:
print(n - i + 1)
return
ans = 0
for card in range(1, n + 1):
if pos[card] != 0:
wait = pos[card] - card + 1
if wait > ans:
ans = wait
print(ans + n)
if __name__ == "__main__":
main()