algorithm - Missing corner cases -


below link problem https://www.hackerrank.com/challenges/and-xor-or/copy-from/16519519
have implemented o(n) solution seems ok (no tle , 29 testcaes passed out of 32). solution failing testcaes , not able find error, surely missing corner cases. hint great help. have posted code below have ran , submitted.

#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <stack>  #define ul unsigned long using namespace std;   ul comp(ul a, ul b){     ul result = ((a&b)^(a|b))&(a^b);     return result; }  int main() {     /* enter code here. read input stdin. print output stdout */        int n;     cin>>n;     vector<ul>ip(n);     for(int i=0;i<n;i++)         cin>>ip[i];     stack<ul>st;     ul result=0;     for(int i=0;i<n;i++){         if(st.empty())             st.push(ip[i]);         else{             result=max(result,comp(st.top(),ip[i]));             while(!st.empty() && st.top()>ip[i]){                 result=max(result,comp(st.top(),ip[i]));                 st.pop();             }             st.push(ip[i]);         }     }     cout<<result;     return 0; } 


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -