This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
class Main { | |
public static void main(String[] args) { | |
int n = 8, m = 5; | |
int[] arr = { 0, 1, 0, 1, 0, 1, 0, 1 }; | |
if(m == 0){ | |
for(int i = 0; i < n; i++){ | |
System.out.print(arr[i] + " "); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Defuse Bomb | |
During the war, the enemy battalion has planted a bomb in your bunker. Your informer has sent you a message of the enemy which contains a list having N numbers and key(K) . The numbers have to be used to construct a sequence to diffuse the bomb. According to your informer, the logic to extract the sequence from the whole message is to replace each number with the sum of the next k elements , if the value of k is positive. When the value of K is negative, the number replaced by the sum of previous K numbers. The series of numbers is considered in a cyclic fashion for the last K numbers | |
Write an algorithm that finds the sequence to defuse the bomb | |
Input Format | |
Input to the function consist of three arguments | |
size , no of elements in the sequence | |
key , represents the K value | |
message, represents the sequence | |
Constraints | |
0<= size <= 10^5 |