"I want to ask a question" - Ask them all here!

Hi @beginner_1111 we have a Youtube channel in which we are constantly posting videos related to Data Structures & Algorithms. Currently we are doing a Dynamic Programming series of 15 days in which we are taking every day a single question which teaches a new concept of DP. Here is the link of series.
Youtube DP series

@devakarthik ou haven’t declared the size of the vector.
either write: vector v(10);
or while taking the value write: cin>>x; v.push_back(x);

Check out Errichto’s YT channel , he has explained concepts of dynamic programming very nicely, there

Regarding Graphs

I am learning graph algorithms and am looking for places to practise problems. Any suggestions will be helpful

I recently started with the codechef DSA learning series, and I have noticed that the questions that I solve there (from the contests section), does not appear on the list of solved problems on my profile page and neither on the recent submissions section. Why??

help i want help in practice problem
problem code [CHFICRM]
my code :
#include
using namespace std;

int main()
{
int T;
cin>>T;
while(T–)
{
int N;
cin>>N;
int a[N],c5=0,c10=0,b=1;

for(int i=0;i<N;i++)
      cin>>a[i];

for(int i=0;i<N;i++)
  {
      if(a[i]==5)
          c5++;
      else if(a[i]==10)
      {
          if(c5>0)  {c5--;c10++;}
          else     {cout<<"\nNO";b=0;break;}
      }
      else if(a[i]==15)
      {
          if(c5>1)        c5-=2;
          else if(c10>0)   c10--;
          else           {cout<<"\nNO";b=0;break;}
      }
  }
  if(b==1) cout<<"\nYES";

}
return 0;
}

i can’t get complete 100 point in this…please help me !!

In the third case, a[i]==15 just reverse the sequence of the statements and see the magic.

It is always better to have two 5 Rs for change rather than one 10 Rs so that you can give the change to atleast two customers now. In your logic, just one customer can be returned the change.

Also, next time just add the link to your solution. Coz (me humms)“I want it that way”

I get 40 points (task 1) in it …but for next 60 points (task 2) its says use same constraints and i used them but still it does not give me the 60 points
https://www.codechef.com/viewsolution/34525966

Whenever I submit my code I get the wrong answer.

Can anyone tell me what’s wrong with my code, where am I going wrong?

Code Chef Icecream : Contest Code:PRACTICE
Problem Code:CHFICRM

import java.util. ;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int tc = sc.nextInt();

   while(tc !=0)
   {
       
       int sum[] =new int[1];
       int count =0;
       int N = sc.nextInt();
       int diff[] = new int[N];
       int a[] = new int[N];
       
       for(int j=0;j<N;j++)
       {
          a[j] = sc.nextInt();
          //System.out.println("a["+j+"]: "+ a[j]);
       }
       for(int j=1;j<N;j++)
       {
          if(a[0] == 5)
           {
             sum[0] = sum[0]+a[j-1];
             //System.out.println("sum["+0+"]: "+ sum[0]);
             diff[j-1] = a[j] - 5;
             if(diff[j-1] == a[j-1])
             {
                 count = count +1;
             }
             else if( diff[j-1] ==0 || a[j] == 5)
             {
               count= count+1;   
             }
             else if(a[j] == 15)
             {
                 if(sum[0]>=diff[j-1])
                 {
                     count = count +1;
                 }
                
             }
             
             if(j== (N-1) && count == (N-1))
             {
                     System.out.println("YES");
                    // System.out.println("if sum["+0+"]: "+ sum[0]);
                     sum[0] =0;
             }
             else if(count < (N-1) && j==(N-1))
             {
                 System.out.println("NO");
                 //System.out.println("sum["+0+"]: "+ sum[0]);
                 sum[0] =0;
             }
                 
             
             
            }
          else
            {
              System.out.println("NO");
              sum[0]=0;
            }
       }
   
       tc--;
   }
  
}

}

Problem in beginner questions -
This is a question for finding GCD and LCM, and my code is not being accepted in spite of getting desired outcomes -
CodeChef: Practical coding for everyone

#include <stdio.h>

int main(void) {
// your code goes here
int t;
scanf(“%d”, &t);
for(int i = 0; i<t; i++){
int a, b, gcd;
scanf(“%d %d”, &a, &b);
int c = a>b? b : a;
for(int n = 1; n<=c; n++){
if(a % n == 0 && b % n == 0){
gcd = n;
}
}
int lcm = (a*b)/gcd;
printf(“%d %d\n”, gcd, lcm);
}
return 0;
}

Can someone please tell me why it is so?

Format your code. Use ``` symbol at the start and the end of code.

See the range of a and b. a*b will not fit in int

Just use __gcd(a, b) to find the GCD.

Thanks so much, I didn’t know how to format here

Hello there, I am struggling to understand a piece of code. The question is Circular RMQ. My solution 1xLDk5 - Online C++0x Compiler & Debugging Tool - Ideone.com here gives WA. But just modifying the update and query function as the code below gives correct ans. Please anyone tell me what is happening here ?

> void update(ll node, ll low,ll high,ll l, ll r, ll val){
 
	
	
	if(marked[node]!=0){
		tree[node] += marked[node];
		if(low !=high){
			marked[2*node] += marked[node];
			marked[2*node+1] += marked[node];	
		}
			
		marked[node] = 0;
	}
 
	if(r<l) return;
 
	if(low ==l && high == r){
		tree[node]+= val;
		if(low != high){
			marked[2*node] += val;
			marked[2*node+1] += val;	
		}	
		return;
	}
 
 
	ll mid = (low+high)/2;
 
	update(2*node,low,mid,l,min(r,mid),val);
	update(2*node+1,mid+1,high,max(mid+1,l),r,val);
 
	tree[node] = min(tree[2*node],tree[2*node+1]);
}
 
>ll query(ll node, ll low, ll high, ll l, ll r){
 
	
 
	if(marked[node]){
		tree[node] += marked[node];
		if(low !=high){
			marked[2*node] += marked[node];
			marked[2*node+1] += marked[node];	
		}	
		marked[node] = 0;
	}
 
	if(r<l) return inf;
 
	if(low == l && high == r){
		return tree[node];
	}
 
	ll mid = (low+high)/2;
 
	ll left = query(2*node,low,mid,l,min(r,mid));
	ll right = query(2*node+1,mid+1,high,max(mid+1,l),r);
 
	return min(left,right);
 
}

1). Have you ever taken any test with Infosys Limited?
2. Have you ever been selected for Interview with Infosys Limited?

These questions are asked in Infosys Recruitment Registration Form, I have given InfyTQ and HackwithInfy exams should I check ‘YES’ in that question and also I have a an got an Interview for SES Role in Infosys which is due, should I check ‘YES’ in this also and if yes than what date should I put in ??

Don’t you know have you taken test or selected for interview?

I don’t know in which context they are asking, InfyTQ and HackwithInfy are given by all, moreover on checking ‘yes’, they are asking for dates, and we have not yet got any dates for Interview !

complex complex::operator+(complex c)
{
    complex tmp;
    tmp.real=real+c.real;
    tmp.imag=imag+c.imag;
    return tmp;
}

Can anyone please tell the pseudo code for operator overloading?