Skip to content

Instantly share code, notes, and snippets.

View jnhemant's full-sized avatar
🏠
Working from home

Hemant Jain jnhemant

🏠
Working from home
View GitHub Profile
@jnhemant
jnhemant / FAULTY STREET LIGHTS.java
Created August 31, 2020 10:01
Faulty Street Lights Coding Challenge
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] + " ");
}
@jnhemant
jnhemant / Bomb Diffusion.java
Created August 31, 2020 09:44
Coding challenge
/*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