Posts

Directi Online Interview Question :- Two non-overLapping subarrays of size k which gives maximum sum

Directi Online Interview Question. Two non-overLapping subarrays of size k which gives maximum sum. This is a 1-D Dp approach ,in O(n) time-complexity. #include<bits/stdc++.h> using namespace std; int pre[1000],a[10000],dp[1000]; int main() {     int n,k;     cin>>n>>k;     for(int i=1;i<=n;i++) cin>>a[i];         pre[0]=0;         pre[1]=a[1];         dp[k]=pre[k];    ///upto length k     for(int i=2;i<=n;i++) pre[i]=pre[i-1]+a[i];     for(int i=k+1;i<=n;i++) dp[i]=max(dp[i-1],pre[i]-pre[i-k]);     int ans=0;     for (int i=k;i<=n;i++){     ans = max(ans,dp[i-k]+pre[i]-pre[i-k]);}     cout<<ans<<endl;     return 0; }

Women safety and security android app

Image
                                                Download Link: https://play.google.com/store/apps/details?id=comm.Kishlay.screamDetector&hl=en "Chilla" is a personal safety & security app that can be triggered by just a shrill scream . It totally removes the hassles of unlocking the phone or opening the app. It has been found that in cases where someone follows a girl / women or eve-teases her , she generally doesn't calls out to parents or police and if they attack her , the app is of no use to her then. In that situation scream is a natural reaction and tapping that is the best possible way to bring her help. The apps can be triggered by: 1. Scream 2.Pressing power Button 5 times After Trigger, it does the following 1.Sends SMS with location 2.Sends Email with Audio Recording 3.Automatically places a call If a scream is detected the a...

D-query :spoj (MO) (for only queries in range )

                                              http://www.spoj.com/problems/DQUERY/en/                                           DQUERY - D-query In this question , the concept of rearranging queries is used , the method known as "MO".  In the question, it is asked to find total different numbers present in the range [l,r] . "add" and "del" functions are written accordingly. #include<bits/stdc++.h> using namespace std; int readInt () { bool minus = false; int result = 0; char ch; ch = getchar(); while (true) { if (ch == '-') break; if (ch >= '0' && ch <= '9') break; ch = getchar(); } if (ch == '-') minus = true; else result = ch-'0'; while (true) { ch = getchar(); if...

Question which include only Queries. (MO) concept

                                   http://codeforces.com/problemset/problem/221/D                                           D. Little Elephant and Array In this question ,we used the concept of MO , i.e. idea of rearranging the queries according to our beneficial. Firstily , we sort the queries using this cmp function . In all the questions in which ,the concept of MO is used "cmp" is same and  four "while loops"  will be same. :) we just have to change the "add" and "del"  functions for each question. :P #include<bits/stdc++.h> using namespace std; long long int readInt () { bool minus = false; long long int result = 0; char ch; ch = getchar(); while (true) { if (ch == '-') break; if (ch >= '0' && ch <= '9') break; ch = g...

All possible sub-matrices sums.

                                              Save the nature https://www.codechef.com/problems/SVNTR (Lunch Time oct 2015)  In this problem , you have to count number of sub-matrices whose sum is less than or equal to k (given). Approach for this problem : firstly calculate the all possible column sum , i.e for c number of columns ,there will be c*(c+1)/2 columns created.  for example : 1 2 3                                 1  3  6   2   5   3                        4 5 6                 --->>>     4  9  15  5  11  6   after creating "b" matrix from the given "a"  matrix.  Calculate all p...

use of sscanf , takes interger from messy string R23C55.. or R2323434C44554

                                          http://codeforces.com/contest/1/problem/B                                                       B. Spreadsheets 55 = BC 27 = AA 28 = AB sscanf takes out number from a messy string input : for example : if the input is R5564C757 , it takes (sscanf(s,"  %*c   %d    %*c     %d  ",&x,&y);  x=5564  y=757 #include<cstdio> #include<bits/stdc++.h> using namespace std; void g(int t) {  if(t)  {  g((t-1)/26);  putchar(65+(t-1)%26);  } } int main() {   int n,x,y;   char s[64],*p;   for(scanf("%d ",&n);n--;)   {     gets(s);     if(sscanf(s,"  ...

No. of subsets whose gcd is 1

                                                                     Subtraction Game 2                                       https://www.codechef.com/problems/AMSGAME2                        It is only a branch and bound type of recursion. #include<bits/stdc++.h> using namespace std; long long int n,i; long long int a [ 1000 ] ; long long int dp [ 70 ] [ 50010 ] ; long long int go ( long long int cur_indx, long long int cur_gcd ) { if ( cur_indx>=n && cur_gcd== 1 ) return 1 ; else if ( cur_indx>=n && cur_gcd!= 1 ) return 0 ; if ( dp [ cur_ind...