CodeChef Starters 187– Compete, Solve & Get All Solutions! 🔥
CodeChef Contest 187 – All Questions Solved FREE 💻🔥 | 21 May 2025 | 3⭐ Rated
👇Scroll down to get all solutions!👇
Are you ready for another exciting CodeChef-rated contest? Starters 187 is here to test your coding skills and problem-solving abilities! Whether you're a beginner or an intermediate coder (rated up to 5 stars), this is your chance to compete, improve, and rank up.
🗓️ Contest Date: May 21, 2025
⏰ Time: 08:00 PM – 10:00 PM IST | 🕒 Duration: 2 Hours
🏆 Contest Name: CodeChef Starters 187
🚨 Note: The Code of Conduct has been updated — make sure to follow the latest rules!!
🔥 Get All Contest Solutions!
📢 Join now and never miss any updates!
👉 Join Telegram channel Now
👇Scroll down to get all solutions!👇
#Promotion
🚀 क्या आप Engineering Student हैं?
और अब तक अपना Resume, Portfolio Website, या Major/Minor Project नहीं बनाया है?
तो अब 😌 चिंता की कोई बात नहीं!
अगर आपको इन सभी चीज़ों को बनवाने में Help या Guidance चाहिए,
तो बस हमें 📱 WhatsApp कीजिए!
👨💻 हम हैं TechKalaA Agency – एक ऐसा प्लेटफॉर्म जो Students के सपनों को देता है 💻 Digital Wings!
🎯 हमारे Services:
🔹 📚 Major/Minor Project Development (College-ready)
🔹 🌐 Personal Portfolio Website (Job-ready design)
🔹 📄 Resume Building – सिर्फ ₹100 से शुरू!
🔹 ⚡ Hackathon Prototypes
🔹 🤖 AI/ML-Based Projects
📞 तो फिर देरी किस बात की है?
अभी WhatsApp करें और अपनी Tech Journey की शुरुआत करें!
🔗Visit Our Website: techkalaA.in
💬 DM us on WhatsApp: Message now
📱 Call us: 9479314263
✨ Tech KalaA – हम आपके साथ हैं,
आपके सपनों को साकार करने के लिए! 💫
Please Subscribe Our YouTube Channel
NOTE :- Don’t copy the full code — use the logic.
We're not responsible for plagiarism issues.
Thank you!
Q1 Solutions -
n= int(input())
print(3*n)
Q2 Solutions -
T = int(input())
for _ in range(T):
Aay, Rathour, K = map(int, input().split())
total = Aay * Rathour
max_alice = 0
if K == 0:
max_alice = total
elif K > total:
max_alice = 0
else:
for i in range(1, Aay):
bob = i * Rathour
if bob >= K:
max_alice = max(max_alice, total - bob)
bob = (Aay - i) * Rathour
if bob >= K:
max_alice = max(max_alice, total - bob)
for j in range(1, Rathour):
bob = j * Aay
if bob >= K:
max_alice = max(max_alice, total - bob)
bob = (Rathour - j) * Aay
if bob >= K:
max_alice = max(max_alice, total - bob)
print(max_alice)
Q3 Solutions -
T = int(input())
for _ in range(T):
X, Y, K = map(int, input().split())
winner = "Bob"
for first_move in range(1, K + 1):
if X >= first_move:
new_X = X - first_move
if new_X > first_move or Y > first_move:
pass
else:
winner = "Alice"
break
if Y >= first_move:
new_Y = Y - first_move
if new_Y > first_move or X > first_move:
pass
else:
winner = "Alice"
break
print(winner)
Q4 Solutions -
import sys
def solve():
input = sys.stdin.read().split() #Q4 Solution
ptr = 0
T = int(input[ptr])
ptr += 1
for _ in range(T):
N = int(input[ptr])
X = int(input[ptr + 1])
ptr += 2
valid = []
for i in range(1, N + 1): #Q4 Solution
if (i | X) == X:
valid.append(i)
P = [0] * N
used = [False] * (N + 1) # 1-based indexing
valid_set = set(valid)
pairs = []
processed = set()
# Form pairs where i < m_i and m_m_i == i
for i in valid:
if i in processed:
continue
m_i = X & (~i)
if m_i in valid_set and m_i not in processed and m_i != i:
m_m_i = X & (~m_i)
if m_m_i == i and i < m_i:
pairs.append((i, m_i))
processed.add(i)
processed.add(m_i)
# Assign pairs
for a, b in pairs:
P[a - 1] = b
P[b - 1] = a
used[a] = True
used[b] = True
# Process remaining valid indices
for i in valid:
if i in processed:
continue
m_i = X & (~i)
if 1 <= m_i <= N and not used[m_i]:
P[i - 1] = m_i
used[m_i] = True
processed.add(i)
else:
if X == i and not used[i]:
P[i - 1] = i
used[i] = True
processed.add(i)
# Fill the remaining positions
unused = []
for num in range(1, N + 1):
if not used[num]:
unused.append(num)
ptr_unused = 0
for i in range(N):
if P[i] == 0:
P[i] = unused[ptr_unused]
ptr_unused += 1
print(' '.join(map(str, P)))
solve()
Q4 Solutions -
MOD = 998244353
MAXN = 200005
# Precompute dp array
dp = [0] * MAXN
dp[0] = 1
dp[1] = 2
dp[2] = 3
for i in range(3, MAXN):
dp[i] = (dp[i - 1] + dp[i - 3]) % MOD
# Process test cases
T = int(input())
for _ in range(T):
N = int(input())
S = input()
result = 1
index = 0
while index < N:
end = index
# Extend segment while characters alternate
while end + 1 < N and S[end] != S[end + 1]:
end += 1
segment_length = end - index + 1
if segment_length >= 4:
M = segment_length - 3
result = (result * dp[M]) % MOD
index = end + 1
print(result)
Q6 Solutions-
import sys
input = sys.stdin.readline
NEG_INF = -1 << 60
test_cases = int(input()) #Q6 Solution
for _ in range(test_cases):
Aay, required_sum = map(int, input().split())
values = [0] + list(map(int, input().split())) + [0]
allowed = [0] + list(map(int, input().split())) + [0]
prefix_sum = [0] * (Aay + 2)
prefix_sum_withB = [0] * (Aay + 2)
prefix_max = [NEG_INF] * (Aay + 2)
prefix_max_withB = [NEG_INF] * (Aay + 2) #Q6 Solution
for i in range(1, Aay + 1):
prefix_sum[i] = prefix_sum[i - 1] + max(0, values[i])
prefix_sum_withB[i] = prefix_sum_withB[i - 1] + (values[i] if values[i] > 0 and allowed[i] else 0)
prefix_max[i] = max(prefix_max[i - 1], values[i])
prefix_max_withB[i] = max(prefix_max_withB[i - 1], values[i] if allowed[i] else NEG_INF)
best_prefix_total = [NEG_INF] * (Aay + 2)
best_prefix_withB = [NEG_INF] * (Aay + 2)
for i in range(1, Aay + 1):
best_prefix_total[i] = prefix_sum[i] if prefix_sum[i] > 0 else prefix_max[i]
if prefix_sum_withB[i] > 0:
best_prefix_withB[i] = prefix_sum[i]
elif prefix_sum[i] > 0 and prefix_max_withB[i] > NEG_INF:
best_prefix_withB[i] = prefix_sum[i] + prefix_max_withB[i]
elif prefix_max_withB[i] > NEG_INF:
best_prefix_withB[i] = prefix_max_withB[i]
suffix_sum = [0] * (Aay + 3)
suffix_sum_withB = [0] * (Aay + 3)
suffix_max = [NEG_INF] * (Aay + 3)
suffix_max_withB = [NEG_INF] * (Aay + 3)
for i in range(Aay, 0, -1):
suffix_sum[i] = suffix_sum[i + 1] + max(0, values[i])
suffix_sum_withB[i] = suffix_sum_withB[i + 1] + (values[i] if values[i] > 0 and allowed[i] else 0)
suffix_max[i] = max(suffix_max[i + 1], values[i])
suffix_max_withB[i] = max(suffix_max_withB[i + 1], values[i] if allowed[i] else NEG_INF)
best_suffix_total = [NEG_INF] * (Aay + 3)
best_suffix_withB = [NEG_INF] * (Aay + 3)
for i in range(Aay, 0, -1):
best_suffix_total[i] = suffix_sum[i] if suffix_sum[i] > 0 else suffix_max[i]
if suffix_sum_withB[i] > 0:
best_suffix_withB[i] = suffix_sum[i]
elif suffix_sum[i] > 0 and suffix_max_withB[i] > NEG_INF:
best_suffix_withB[i] = suffix_sum[i] + suffix_max_withB[i]
elif suffix_max_withB[i] > NEG_INF:
best_suffix_withB[i] = suffix_max_withB[i]
best_without_B = NEG_INF
best_possible_with_B = NEG_INF
for middle in range(2, Aay):
left = best_prefix_total[middle - 1]
right = best_suffix_total[middle + 1]
best_without_B = max(best_without_B, left + right)
left_B = best_prefix_withB[middle - 1]
right_B = best_suffix_withB[middle + 1]
if left_B > NEG_INF:
best_possible_with_B = max(best_possible_with_B, left_B + right)
if right_B > NEG_INF:
best_possible_with_B = max(best_possible_with_B, left + right_B)
if best_without_B >= required_sum:
print(0)
else:
operations_needed = required_sum - best_possible_with_B
print(max(0, operations_needed))
Q7 Solving Now(Q7 Solution Will Be Uploaded in 1650 Subscribers Or in 100 likes)

bro 4th answer is wrong please update
ReplyDeletedef can_reach(N, M, A, B):
Deleteif A == B:
return N * A == M
diff = A - B
numer = M - N * B
if numer % diff != 0:
return False
x = numer // diff
return 0 <= x <= N
T = int(input())
for _ in range(T):
N, M, A, B = map(int, input().split())
print("Yes" if can_reach(N, M, A, B) else "No")
try this
Tree Colouring (Hard) pls
ReplyDeletewe are solving this
Deletecostly swapping code needed
ReplyDeleteNOT SOLVED
Delete4 is not working bro
ReplyDeleteitni der lagti mia q7 dene ko?
ReplyDeleteQ8 pls
ReplyDeleteAnti Subarray pls
ReplyDelete