Leetcode with dani
Open in Telegram
Join us and let's tackle leet code questions together: improve your problem-solving skills Preparing for coding interviews learning new algorithms and data structures connect with other coding enthusiasts
Show more1 268
Subscribers
+124 hours
-37 days
-730 days
Posts Archive
1 268
â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:
3Output (one possible grouping):
2 8 5 9 3 4 7 6 1Here, 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
ddef 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()
`1 268
âB. Integer Points
â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 / 2For 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
1 268
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
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)1 268
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
1 268
i want to make this channel more usefull for u so .what type of post do u want to see more often?
1 268
Repost from N/a
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!
1 268
Hey Developers! Let me introduce you to an amazing project: an unlimited free phone verification API created by my friend Yonatan. Check it out!
1 268
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
1 268
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!
1 268
I know this one is a little bit harder question â I donât expect you to get the solution right away.
But Iâm sharing it because trying to solve this will help you deeply understand the Binary Indexed Tree (BIT) concept.
You might not get it in one go â and thatâs okay.
Just keep pushing, and eventually it will click.
đ Problem: Create Sorted Array through Instructions
đĽ Helpful video/Ans: YouTube Explanation
Once you solve this, youâll be confident with how BIT works in real problems â from prefix sums to range frequency queries.
