Objective In this challenge, we're going to use loops to help us do some simple math. Task Given an integer, , print its first multiples. Each multiple (where ) should be printed on a new line in the form: N x i = result . Input Format A single integer, . Constraints Output Format Print lines of output; each line (where ) contains the of in the form: N x i = result . Sample Input 2 Sample Output 2 x 1 = 2 2 x 2 = 4 2 x 3 = 6 2 x 4 = 8 2 x 5 = 10 2 x 6 = 12 2 x 7 = 14 2 x 8 = 16 2 x 9 = 18 2 x 10 = 20 Explanation: Here, we just need to use for loops to achieve the result Solution : import java.io.* ; import java.math.* ; import java.security.* ; import java.text.* ; import java.util.* ; import java.util.concurrent.* ; import java.util.regex.* ; public class Solution { public static void main ( String [] args ) throws IOException { BufferedReader bufferedReader = new BufferedReader ( new InputStreamReader ( Syste
Accico Equi Pair:
Ron Wesley has been bit by a three headed snake and Harry Potter is searching for a potion. The Witch promises to tell the ingredients of the medicine if Harry can find equi pair of an array. Listen to the conversation between Harry The witch to know more about equi pairs.
Conversation:-
The Witch : To find the equi pair, you must know how to find the slices first.
Harry : What is a slice?
The Witch : If Z is an array with N elements, a slice of indices (X, Y) is Z[X] + Z[X+1]...Z[Y]
Harry : How can I use it to find equi pair?
The Witch : (a, b) is an equi pair if slice of (0, a-1) = slice of (a+1, b-1) = slice of (b+1, N-1) and b>a+1 and size of array > 4
Input Format : The first line of input has one single integer N where N will be the size of the Array
An array of N integers delimited by white space
Input Constraints : Zi >= 0 and 1<= i <=N
size of array (N) > 4
b > (a+1)
Output Format : Print equi pair in first line in the format ( a,b )
Print slices in the format ( 0,a-1 ), ( a+1,b-1 ), ( b+1,N-1 )
OR
Conversation:-
The Witch : To find the equi pair, you must know how to find the slices first.
Harry : What is a slice?
The Witch : If Z is an array with N elements, a slice of indices (X, Y) is Z[X] + Z[X+1]...Z[Y]
Harry : How can I use it to find equi pair?
The Witch : (a, b) is an equi pair if slice of (0, a-1) = slice of (a+1, b-1) = slice of (b+1, N-1) and b>a+1 and size of array > 4
Input Format : The first line of input has one single integer N where N will be the size of the Array
An array of N integers delimited by white space
Input Constraints : Zi >= 0 and 1<= i <=N
size of array (N) > 4
b > (a+1)
Output Format : Print equi pair in first line in the format ( a,b )
Print slices in the format ( 0,a-1 ), ( a+1,b-1 ), ( b+1,N-1 )
OR
Print "Array does not contain any equi pair" if there are no equi pairs in the array
Sample Input :
10
8 3 5 2 10 6 7 9 5 2
Sample Output :
Indices which form equi pair ( 3,6 )
slices are ( 0,2 ),( 4,5 ),( 7,9 )
Explanation of question:
- Find the equi pair where it splits an array
- if sum of the pairs are equal,printout the indices.
- l should be in starting index 0
- r should be in N-2 index
- compare a[l] and a[r] if a[l] is greater...then decrement r=r-1 and add a[r]+a[r+1] and store in a[r]
- if not l=l+1 and a[l]+a[l-1] =a[l]
- if equal,increment l+1 and r-1 and compute sum after that so sum(l+2,r-2)
Comments
Post a Comment