×

CAKEWALK

None

# PROBLEM:

Given an unsorted array of unique elements, find the position of a specified elements in array’s sorted form.

# QUICK EXPLANATION:

Count the number of elements in an unsorted array which are smaller than the given element.

# EXPLANATION:

Since the length of all songs is unique, if we count the number of songs which have length less than the length of “Uncle Johny”, we know its position in sorted array.

Constraint on the value of N in this problem is very low so many contestants sorted the array and then did binary search for the length of “Uncle Johny” song in the sorted array. This approach also passes well within time limit.

# AUTHOR'S AND TESTER'S SOLUTIONS:

Author's solution will be uploaded soon
Tester's solution can be found here and here

This question is marked "community wiki".

616913
accept rate: 0%

 0 Links to author's and tester's solutions not working. answered 11 Nov '13, 22:08 4.2k●5●23●64 accept rate: 15%
 0 You can also use two pointers at both ends to get a faster time a---is the array of numbers x--- is the number we are trying to find its position after sorting i=0;j=n-1 while(i<=j) if a[i]
 0 I can't figure out why doesn't it work? https://ideone.com/ftTHzI Seems correct to me. PS: Nicely formatted, readable code. answered 02 Jun '16, 10:19 2★jarpit96 1 accept rate: 0%

Why is this code giving wrong answer ?

# include<cstdio>

using namespace std;

int main() {

int T,N,K,i,song;
long long A[102];
scanf("%d",&T);
while(T--)
{
scanf("%d",&N);
for(i=1;i<=N;i++) scanf("%lld",&A[i]);
scanf("%d",&K);
song=0;
for(i=1;i<=N;i++)
{
if (A[i]<A[K]) song++;
}
printf("%d\n",song);
}
return 0;


}

This answer is marked "community wiki".

1
accept rate: 0%

 0 Why this code returns wrong answer?? #include using namespace std; int main() { int T,N,a[100],K,fav,temp=0; cin>>T; for(int k=0;k>N; for(int i=0;i>a[i]; } cin>>K; fav=a[K-1]; for(int j=0;ja[k+1]){ temp=a[k]; a[k]=a[k+1]; a[k+1]=temp; } } } for(int m=0;m
 0 The majority of students think that doing their homework is boring. They do everything accept their homework. If you are one of such students, struggling with the study overload and burden of assignment. Dissertation writing service answered 26 Aug '16, 11:22 0★adam0702 1 accept rate: 0%
 0 The Class Clown Easily identifiable, it is the student who is bored and tries to boycott the class by interrupting constantly with questions away from the topic that develops at that moment. Your goal is to get the attention of the class with your comments and jokes so that everyone laughs. He does not allow his classmates to get involved with the lessons or that someone actively participates in the class as he talks to the students coming to his site. Uk Dissertation Writing Services answered 23 Feb '17, 14:21 0★aanish -1 accept rate: 0%

# include <stdio.h>

int main(void) { int t,s,p[100],p1,i,j,k,b,u1,lst,fst,mid; scanf("%d",&t); for(i=0;i<t;i++) { scanf("%d",&s); for(j=0;j<s;j++) { scanf("%d",&p[j]); } scanf("%d",&u1); p1=p[u1-1];

      for(k=0;k<s-1;k++)
{
for(j=0;j<=s-k-1;j++)
{
if(p[j]>p[j+1])
{
b=p[j];
p[j]=p[j+1];
p[j+1]=b;
}
}
}
for(j=0;j<s;j++)
{
//  printf("%d\t",p[j]);    //sorted
}
//  printf("\n");
fst=0;
lst=s-1;
mid=(fst+lst)/2;
// printf("%d %d %d %d\n",fst,lst,mid,p1);
while(fst<=lst)
{
if(p[mid]<p1)
fst=mid+1;
else if(p[mid]==p1)
{
printf("%d\n",(mid+1));
break;
}
else
lst=mid-1;
mid=(fst+lst)/2;
}

}
return 0;


}

why the answer is coming wrong although i am getting correct answer in online ide

1
accept rate: 0%

 0 https://www.codechef.com/viewsolution/14638375 Why is this working in c99strict compiler but not in c compiler??? What is the difference between the two? answered 22 Jul '17, 16:49 1●1 accept rate: 0%
 0 The lion's share of understudies believe that getting their work done is exhausting. They do everything acknowledge their homework. Get dissertation help UK On the off chance that you are one of such understudies, battling with the examination over-burden and weight of task. answered 09 Aug '17, 12:06 1 accept rate: 0%
 0 Dont stress long challenge are implied for learning that is the reason they give 10 days to take care of issues and since as u portrayed u were not ready to do first q of the current month's long this implies despite everything you need to concentrate on your execution abilities so Dissertation Service alongside critical thinking attempt to center usage aptitudes also Happy coding. answered 09 Aug '17, 13:07 1 accept rate: 0%
 0 We have a wide range of assignment help writers that are experts on a gigantic variety of topics that come under the Assignment help Services in Australia. Assignment Help Australia answered 13 Nov '17, 11:17 0★vincymol 1 accept rate: 0%
 0  #include int main() { int i,j,t,n,k; long long int a[101],e,temp; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=0; i
 0 If you use the phrase that work was a cakewalk or that mission was a cakewalk that means the work was a piece of cake. UK dissertation help Simply accomplished with little or no effort. You six guys! Go carry that Ping-Pong table to the other side of the room = cakewalk. Yo, Fred! Carry the slate pool table up those stairs = not a cakewalk. answered 22 Jan, 15:31 1 accept rate: 0%
 0 You looking for Dentist in Jaipur. We have become a symbol of quality and Endeavour Our self to provide high standards of dental treatment to our patients. We have high standards of sterilization with International sterilization protocols followed . We follow three Phase Sterilization as recommended by American Dental Association. Ekdantam Dental clinic answered 11 Jul, 18:05 -1 accept rate: 0%
 0 We provide the best jaipur sightseeing taxi with Facilities and healthy Relations for Future Bookings.kdcab is here to provide the best experience of traveling of your trip with reliable and affordable cab service in Jaipur. answered 28 Jul, 15:21 0★kdcab -1 accept rate: 0%

hello why don't you give if the editorial says you can accept within time with a binary search???

# include<algorithm>

using namespace std;

# define MAX 101

int medio;

int binary_search(int vec,int i,int j,int m){ if(i>j)return -1; medio = (i+j)/2; if(m>vec[medio])return binary_search(vec,medio+1,j,m); else if(m<vec[medio])return binary_search(vec,i,j-1,m); else medio; } int main(int argc,char argv[],char **env){ int t,n,k,val; scanf("%d",&t);

while(t--){
scanf("%d",&n);
int vec[MAX]{};
for(int i=1;i<=n;i++)
scanf("%d",(vec+i));
scanf("%d",&k);
val = vec[k];
sort(vec+1,vec+n+1);
printf("%d\n",binary_search(vec,1,n,val));
}
return 0;


}

1
accept rate: 0%

Why is thi code giving wrong answer??

# include<stdio.h>

int main() { int t,n,m,k,i,j; long long int a[100],b,temp; scanf("%d",&t); while (t--) { scanf("%d",&n); for(i=0;i<n;i++) {="" scanf("%lld",&a[i]);="" }="" scanf("%d",&k);="" b="a[k-1];" for(i="0;i&lt;n-1;i++)" {="" for(j="0;j&lt;n-1-i;j++)" {="" if(a[j]="">a[j+1]) { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } } for(i=0;i<n;i++) { if(a[i]== b) printf("%d",i+1); } } return 0;

}

1
accept rate: 0%

 -1 Why this code not working ? #include #include int cmp(const void* a, const void* b) { return ( *(int*)a - *(int*)b ); } int search(int a[], int low, int high, int x) { while(lowx) return search(a,low,mid-1,x); else return search(a,mid+1,high,x); } //return 0; } int main(void) { // your code goes here int t,n,i,k,x,j; scanf("%d",&t); while(t--) { scanf("%d",&n); int a[n]; for(i=0;i
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×15,130
×1,558
×15
×3

question asked: 11 Nov '13, 15:03

question was seen: 6,483 times

last updated: 10 Nov, 17:04