Beruflich Dokumente
Kultur Dokumente
You are given with an array of 1s and 0s. And you are given with an integer M, which
signifies number of flips allowed.
You are to apply at most M flip operations to product the longest continuous sequence of 1s
in the array.
For this problem, return the indices of maximum continuous series of 1s in order.
Input Format
First line contains N and M, the size of array and number of flips allowed. Second line
contains N integers, the elements of array a.
Constraints
Output Format
Output two numbers, the starting and the ending index (1-indexed) of the longest Onely
sequence.
In case of multiple answers print the one with lower start index.
Sample Input 0
10 1
1 1 0 1 1 0 0 1 1 1
Sample Output 0
1 5
Given an array, Mister Arr the owner of the array wants to move each element k places to its
left. I.E. the array a[0],a[1],a[2],...a[n] becomes a[1],a[2]...a[n],a[0] after moving one place to
the left. Note that the first element becomes the last element after each rotation. Mister Arr
was up all night watching a football match and hence is sleeping now. He has given you the
task to rotate the entire array K places to its left.
Input Format
The first line contains two space-separated integers denoting the respective values of n (the
number of integers) and k (the number of left rotations you must perform). The second line
contains n space-separated integers describing the respective elements of the array's initial
state.
Constraints
Output Format
Print a single line of n space-separated integers denoting the final state of the array after
performing d left rotations.
Sample Input 0
5 4
1 2 3 4 5
Sample Output 0
5 1 2 3 4
Write a program to print 1-n^2 in a spiral in a spiral order in a square matrix.
Input Format
Constraints
Output Format
Sample Input 0
Sample Output 0
1 2 3 4
12 13 14 5
11 16 15 6
10 9 8 7
Sample Input 1
Sample Output 1
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
Circular_Matrix
import java.util.*;
class Circular_Matrix
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of elements : ");
int n = sc.nextInt();
while(k<=n*n)
{
for(int i=c1;i<=c2;i++)
{
A[r1][i]=k++;
}
for(int j=r1+1;j<=r2;j++)
{
A[j][c2]=k++;
}
for(int i=c2-1;i>=c1;i--)
{
A[r2][i]=k++;
}
for(int j=r2-1;j>=r1+1;j--)
{
A[j][c1]=k++;
}
c1++;
c2--;
r1++;
r2--;
}
Football
import java.util.Scanner;
import java.util.Scanner;
N = s.nextInt();
if(N >= 1)
M = s.nextInt();
arr[temp] = s.nextInt();
if(arr[temp] == 0)
i++;
else
j++;
}
if(i > j)
finalArr = replaceOne(arr,M);
largestOccurence(finalArr, 0);
else
finalArr = replaceZero(arr,M);
largestOccurence(finalArr, 1);
Integer[] temp = a;
Integer[] temp1 = a;
temp = a;
if(a[fast] == 0)
--k;
if(a[slow] == 0)
{
temp[slow] = 1;
++k;
len1 = len1 > (fast - slow + 1)? len1 :(fast - slow + 1);
temp1 = temp;
len = len1;
return temp1;
Integer[] temp = a;
Integer[] temp1 = a;
if(a[fast] == 1)
--k;
if(a[slow] == 1)
temp[slow] = 0;
++k;
}
}
len1 = len1 > (fast - slow + 1)? len1 :(fast - slow + 1);
temp1 = temp;
temp = a;
len = len1;
return temp1;
if(len == 0)
startindex = start;
if(a[start] == k)
len++;
start++;
else
len1 = len;
endindex = start - 1;
startindexF = startindex;
start = start+1;
len = 0;