7 359
Подписчики
-324 часа
-237 дней
-11330 день
Архив постов
AlphaGrep slots are opened✅
Time : 7PM
💯 clearance for your exam
Contact: @MLCODER2
VIRTUSA exam cleared ✅✅
Got communication round mail ✅
Proofs :
https://t.me/python_java_Coding/8812?single
Contact : @MLCODER2
WIPRO EXAM✅✅
60mcqs + ESSAY WRITING✅✅
Contact : @MLCODER2
from collections import defaultdict
def getMinReplacement(arr):
n = len(arr)
d= {}
x=[]
map= defaultdict(list)
for idx, v in enumerate(arr):
map[v].append(idx)
maxi = 0
for val, p,in map.items():
segments = 1
for i in range(1, len(p)):
if p[i] != po[i-1] + 1:
segments += 1
maxi = max(maxi, segments)
return maxi - 1
Send your DeShaw questions to @MLCODER2
FOR FREE SOLUTIONS
DeShaw OA help available ✅
100% CLEARANCE FOR YOUR EXAM ✅
Contact: @MLCODER2
VIRTUSA SLOTS ARE AVAILABLE ✅
💯 clearance for your exam
Contact: @MLCODER2
import java.util.*;
public class Main{
public static Node findchain(Node chain1, Node chain2) {
int len1 = getLength(chain1);
int len2 = getLength(chain2);
Node ptr1 = chain1;
Node ptr2 = chain2;
if (len1 > len2) {
int diff = len1 - len2;
while (diff-- > 0) ptr1 = ptr1.next;
} else {
int diff = len2 - len1;
while (diff-- > 0) ptr2 = ptr2.next;
}
while (ptr1 != null && ptr2 != null && ptr1 != ptr2) {
ptr1 = ptr1.next;
ptr2 = ptr2.next;
}
Node mergePoint = ptr1;
int beforeMerge1 = getDistance(chain1, mergePoint);
int beforeMerge2 = getDistance(chain2, mergePoint);
Node result = null;
if (beforeMerge1 < beforeMerge2 || (beforeMerge1 == beforeMerge2)) {
result = cloneUntil(chain1, mergePoint);
appendTail(result, mergePoint);
} else {
result = cloneUntil(chain2, mergePoint);
appendTail(result, mergePoint);
}
return result;
}
private static int getLength(Node head) {
int count = 0;
while (head != null) {
head = head.next;
count++;
}
return count;
}
private static int getDistance(Node head, Node stop) {
int count = 0;
while (head != stop) {
head = head.next;
count++;
}
return count;
}
private static Node cloneUntil(Node head, Node stop) {
if (head == stop) return null;
Node newHead = new Node(head.value);
Node current = newHead;
head = head.next;
while (head != stop) {
current.next = new Node(head.value);
current = current.next;
head = head.next;
}
return newHead;
}
private static void appendTail(Node head, Node tailStart) {
if (head == null) return;
while (head.next != null) {
head = head.next;
}
head.next = tailStart;
}
}
