CODE WITH VIRUS
Open in Telegram
1 278
Subscribers
No data24 hours
No data7 days
No data30 days
Posts Archive
1 278
Largest sum cycle code
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class LargesSumCycle {
public static int solution(int arr[])
{
ArrayList<Integer> sum = new ArrayList<>();
for(int i = 0; i < arr.length; i ++)
{
ArrayList<Integer> path = new ArrayList<>();
int j = i;
int tempSum = 0;
while(arr[j]<arr.length && arr[j]!=i && arr[j]!=-1 && !path.contains(j))
{
path.add(j);
tempSum+=j;
j=arr[j];
if(arr[j]==i)
{
tempSum+=j;
break;
}
}
if(j<arr.length && i == arr[j])
sum.add(tempSum);
}
if(sum.isEmpty())
return -1;
return Collections.max(sum);
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int testCases = scanner.nextInt();;
for(int loop=0; loop<testCases; loop++){
int numofBlocks = scanner.nextInt();
int array[] = new int[numofBlocks];
int src, dest;
for(int i=0; i<numofBlocks; i++){
array[i]=scanner.nextInt();
}
System.out.println(solution(array));
}
scanner.close();
}
}
Juspay code
💽 Share https://t.me/coding_solution 😎
1 278
Q14) it is believed
D
Suite
Q15) the minster
D
Defeated
Join This Channel for All Answers
👉 @coding_solution
👉 @coding_solution
1 278
Q8) industry
B
3124
Q9) indian
C
Abcd
Q10) one way
A
Adbc
Q11) coming
C
Sq
Q12) in response
D
Placed
Q13) there
A
Not a
Join This Channel for All Answers
👉 @coding_solution
👉 @coding_solution
1 278
Q2) ben hur
A
Of a
Q3) the 350 metre
D
And building
Q5) it may
D
Grapple
Q6) when
A
Not to
Q7) ok
B
An angel investor
Join This Channel for All Answers
👉 @coding_solution
👉 @coding_solution
1 278
Q14) a boy goes
A.
4.735km.
Q15) the speed
C
1520km
Q16) two
A
32 cm
Q17) a continous
A
1/5
Q18) 80
Join This Channel for All Answers
👉 @coding_solution
👉 @coding_solution
1 278
Share guys all from 14th question.
We will send all answers after 5 min.. Untill then share
If not share we will stop
Start now ❤️
1 278
Q10) an electric
A
15.5
Join This Channel for All Answers
👉 @coding_solution
👉 @coding_solution
1 278
Q7) at a certain
A
7.9
Q8) a man earns
D
98,400
Join This Channel for All Answers
👉 @coding_solution
👉 @coding_solution
1 278
✅ TCS NQT 6 PM Slot Answers :
1) 1080
2) 2
3) 0.2
4) 52
Join This Channel for All Answers
👉 @coding_solution
👉 @coding_solution
