def getMinimumOperations(tree_nodes, tree_from, tree_to, initial, expected):
adj = [[] for _ in range(tree_nodes)]
for i in range(len(tree_from)):
adj[tree_from[i]].append(tree_to[i])
adj[tree_to[i]].append(tree_from[i])
parent = [-1] * tree_nodes
depth = [0] * tree_nodes
children = [[] for _ in range(tree_nodes)]
def dfs(node, par):
for next_node in adj[node]:
if next_node != par:
parent[next_node] = node
depth[next_node] = depth[node] + 1
children[node].append(next_node)
dfs(next_node, node)
dfs(0, -1)
def flip_subtree(curr_values, node):
new_values = curr_values.copy()
stack = [node]
while stack:
current = stack.pop()
if current % 2 == 0:
new_values[current] = 1 - new_values[current]
stack.extend(children[current])
return new_values
def get_path_to_root(node):
path = []
while node != -1:
path.append(node)
node = parent[node]
return path
operations = 0
current = initial.copy()
for node in range(tree_nodes):
if current[node] != expected[node]:
path = get_path_to_root(node)
found = False
for ancestor in path:
test_values = flip_subtree(current, ancestor)
if test_values[node] == expected[node]:
current = test_values
operations += 1
found = True
break
if not found:
return -1
return operations if current == expected else -1
UkG
UkG || 2yrs EXPERIENCE Help done ✔️
Coding+ git repository💯 🎉
DM @Mrtrueliving_ix, For help
#UkG #2yrs_Experience
Coding+ git repository
DM @Mrtrueliving_ix, For help
#UkG #2yrs_Experience
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Wipro Elite Help available
DM those who need help
@Mrtrueliving_ix
@Mrtrueliving_ix
Previous Helping proofs
https://t.me/code_alphix/5153
https://t.me/code_alphix/5092?single
DM those who need help
@Mrtrueliving_ix
@Mrtrueliving_ix
Previous Helping proofs
https://t.me/code_alphix/5153
https://t.me/code_alphix/5092?single
Limited slots available book your slots
Those who need 💯 Test Clearance 🤗
❤1👀1
All placement Help available
🚫 Wipro Elite ( all time slots)
https://t.me/code_alphix/4859
🚫 IBM
🚫 Amazon SDE
🚫 Cognizant
🚫 Capgemini
🚫 CGI
🚫 Revature
🚫 UST
🚫 Meesho (17th last)
Other OA available
On || off campus
Those who need 💯 placement
DM @Mrtrueliving_ix
@Mrtrueliving_ix
https://t.me/code_alphix/4859
Other OA available
On || off campus
Those who need 💯 placement
DM @Mrtrueliving_ix
@Mrtrueliving_ix
Remote access🔔
Please open Telegram to view this post
VIEW IN TELEGRAM
❤1🔥1
👌1
def solution(S, K):
n = len(S)
res = float('inf')
for i in range(n - K + 1):
t = S[:i] + S[i + K:]
compressed = ''
count = 1
for j in range(1, len(t)):
if t[j] == t[j - 1]:
count += 1
else:
compressed += t[j - 1] + (str(count) if count > 1 else '')
count = 1
if t:
compressed += t[-1] + (str(count) if count > 1 else '')
res = min(res, len(compressed))
return res
Microsoft
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
def solution(s, t):
n = len(s)
sw = s[0] > t[0]
c = 0
for k in range(n):
if s[k] != t[k]:
if (s[k] > t[k]) == sw:
c += 1
return c
Microsoft
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Wipro 12 pm || Offcampus Help done
Test accomplished✅
Those who need Test Clearance 💯
DM
@Mrtrueliving_ix @Mrtrueliving_ix
#WiproElite #offCAMPUS #Round1
Test accomplished
Slot - 1✨
Those who need Test Clearance 💯
DM
@Mrtrueliving_ix @Mrtrueliving_ix
#WiproElite #offCAMPUS #Round1
Please open Telegram to view this post
VIEW IN TELEGRAM
Wipro 12 pm || ON campus Help done
All MCQs + coding+ essay writing✔️ 💯
Test accomplished✅
Those who need Test Clearance
DM
@Mrtrueliving_ix @Mrtrueliving_ix
#WiproElite #OFFCAMPUS #Round1
All MCQs + coding+ essay writing
Test accomplished
Slot - 2✨
Those who need Test Clearance
DM
@Mrtrueliving_ix @Mrtrueliving_ix
#WiproElite #OFFCAMPUS #Round1
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM