Menu
- Scherlokk 3 1 5 – Find And Compare Files Included Files
- Scherlokk 3 1 5 – Find And Compare Files Included Software
![Compare Compare](https://img.magimg.com/uploads/scherlokk.jpg)
Scherlokk 3 1 5 – Find And Compare Files Included Files
Sherlock Holmes, fictional character created by the Scottish writer Arthur Conan Doyle.The prototype for the modern mastermind detective, Holmes first appeared in Conan Doyle’s A Study in Scarlet, published in Beeton’s Christmas Annual of 1887. Principle 5 0 download free. As the world’s first and only “consulting detective,” he pursued criminals throughout Victorian and Edwardian London, the south of England. Read about HMO plans, which require you to go to doctors, other health care providers, or hospitals on the plan's list, unless you need emergency care. You may also need to get a referral from your primary care doctor to see a specialist.
Scherlokk 3 1 5 – Find And Compare Files Included Software
PROBLEM (https://www.hackerrank.com/challenges/sherlock-and-array)
Watson gives an array A1,A2..AN to Sherlock. Then he asks him to find if there exists an element in the array, such that, the sum of elements on its left is equal to the sum of elements on its right. If there are no elements to left/right, then sum is considered to be zero. Formally, find an i, such that, A1+A2..Ai-1 = Ai+1+Ai+2..AN.
Input Format
The first line contains T, the number of test cases. For each test case, the first line contains N, the number of elements in the array
A. The second line for each testcase contains N space separated integers, denoting the array A.
Output Format
For each test case, print YES if there
exists an element in the array, such that, the sum of elements on its left is equal to the sum of elements on its right, else print NO.
Constraints
1 ≤ T ≤ 10
1 ≤ N ≤ 105
1 ≤ Ai ≤ 2*104 for 1 ≤ i ≤ N
Sample Input
2
3
1 2 3
4
1 2 3 3
Sample Output
NO
YES
Explanation
For test case 1, no such index exists.
For test case 2, A[1]+A[2]=A[4], therefore index 3 satisfies.
SOLUTION
#include<stdio.h>
int main(){
int T,t,n,i,j;
scanf('%d',&T);
for(t=0;t<T;t++){
scanf('%d',&n);
int a[n];
for(i=0;i<n;i++){
scanf('%d',&a[i]);
}
int first=0,last=0;
for(i=1;i<n;i++){
last+=a[i];
}
for(i=0;i<n-1;i++){
if(firstlast){
printf('YESn');
break;
}
first+= a[i];
last-= a[i+1];
}
if(in-1 && n!=1)
printf('NOn');
if(n1)
printf('YESn');
}
return 0;
}
Watson gives an array A1,A2..AN to Sherlock. Then he asks him to find if there exists an element in the array, such that, the sum of elements on its left is equal to the sum of elements on its right. If there are no elements to left/right, then sum is considered to be zero. Formally, find an i, such that, A1+A2..Ai-1 = Ai+1+Ai+2..AN.
Input Format
The first line contains T, the number of test cases. For each test case, the first line contains N, the number of elements in the array
A. The second line for each testcase contains N space separated integers, denoting the array A.
Output Format
For each test case, print YES if there
exists an element in the array, such that, the sum of elements on its left is equal to the sum of elements on its right, else print NO.
Constraints
1 ≤ T ≤ 10
1 ≤ N ≤ 105
1 ≤ Ai ≤ 2*104 for 1 ≤ i ≤ N
Sample Input
2
3
1 2 3
4
1 2 3 3
Sample Output
NO
YES
Explanation
For test case 1, no such index exists.
For test case 2, A[1]+A[2]=A[4], therefore index 3 satisfies.
SOLUTION
#include<stdio.h>
int main(){
int T,t,n,i,j;
scanf('%d',&T);
for(t=0;t<T;t++){
scanf('%d',&n);
int a[n];
for(i=0;i<n;i++){
scanf('%d',&a[i]);
}
int first=0,last=0;
for(i=1;i<n;i++){
last+=a[i];
}
for(i=0;i<n-1;i++){
if(firstlast){
printf('YESn');
break;
}
first+= a[i];
last-= a[i+1];
}
if(in-1 && n!=1)
printf('NOn');
if(n1)
printf('YESn');
}
return 0;
}