Skip to main content

SER15


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int main()
{
   //a*(a+1)/2
   ll N;
   cin>>N;
  int a=0;
  int val=2,n=2;
  if(val>n/2)
  {
  }
   vector <ll> A;
   for(int i=0;a<=N;i++)
   {
       a = (i*(i+1))/2;
           A.push_back(a);
   }
   /* for(auto i = A.begin();i!=A.end();i++)
    {
        cout<<*i<<" ";
    }*/
   ll l = A.size();
  bool t ;
   for(int i=0;i<l;i++)
   {
       for(int j=0;j<l;j++)
       {
           if(N==A[i]+A[j])
           {
             t= true;
             break;
             
           } else{
               t = false;
           }
       }
       if(t==true)
       {
           break;
       }
   }

if(t)
{cout<<"YES"<<endl;
}
  else
  {cout<<"NO"<<endl;
  }

    return 0;
}

Comments

  1. need code for this Q18
    .
    .
    Given a Binary Tree as pre-order traversal input which has both positive and negative nodes, the task is to find maximum sum level in it.Using level order traversal of tree and queue data structure,solve the problem.For example , A binary tree with pre-order traversal as {4,2,-1,3,6,5,7}:
    4
    / \
    2 6
    / \ /\
    -1 3 5 7
    Sum of all nodes of 0th level is 4
    Sum of all nodes of 1th level is 8
    Sum of all nodes of 2nd level is 14
    Hence maximum sum is 14

    Mandatory declarations are "struct node *Right;", "struct node *Left;"

    INPUT:
    The first line of input is the number of nodes in tree N and then followed by the nodes as in pre-order traversal.

    OUTPUT:
    The output should be the maximum level sum of the tree.

    ReplyDelete

Post a Comment

Popular posts from this blog

SORT 14 #include<stdio.h> int main() {   int a[1001];  int n,i,j,t,swap,temp,k,m,s,r,x=1,ss=1,c=1,f=0;  scanf("%d", &t);  while(t--)  {      swap=0;      scanf("%d %d  %d", &m,&s,&n);          for(i=0; i<n; i++){          scanf("%d", &a[i]);      }      for(i=0; i<n-1; i++){          //temp=i;          for(j=0;j<n-i-1;j++){              //temp=a[j];              if(a[j]>a[j+1]){                   temp=a[j];                   a[j]=a[j+1];                   a[j+1]=temp;                   ...

DS

SORT 3 #include <iostream> using namespace std; void printArr(int arr[], int size) { for(int i=0;i<size;i++) { cout<<arr[i]<<" "; }   cout<<endl; } void sort(int a[],int n) { for(int i=0;i<n-1;i++)     {       for(int j=0;j<n-i-1;j++)       {       if(a[j]>a[j+1])       {       int temp=a[j];         a[j]=a[j+1];         a[j+1]=temp;       }       }       if(i==2)         printArr(a,n);     } } int main() {   int n;   cin>>n;   int a[n];   for(int i=0;i<n;i++)   { cin>>a[i];     }   sort(a,n);   cout<<"Sorted array:";   printArr(a,n); return 0; }
SRM CCC HACKER RANK: Binary string duplication: python import sys s = [0] while len(s) < 1000:     s += [1-x for x in s]           def duplication(s, x):     return s[x]           q = int(input().strip()) for a0 in range(q):     x = int(input().strip())     result = duplication(s,x)     print(result)