No actually it is bounded by O(m^n) where m is same as you stated but n is floor(n/2) in nth sum problem.
namangoyal
@namangoyal
Posts made by namangoyal

RE: 4Sum C++ solution with explanation and comparison with 3Sum problem. Easy to understand.

RE: Memory limit exceeded
Your code is correct just one small change. You are passing the vectors by value. Every time the recursion happens a copy of your vectors are created. Just add '&' in your maketree function before preorder and inorder and everything will work.
TreeNode * maketree(vector <int> &preorder,vector<int> &inorder,int *index,int l,int r)

RE: My topdown (c++) solution is timing out...even with memoizing? haaaaalp!!!
You can try my following concise solution(top down memoized). It gets accepted but still is very slow for C++ solution:
class Solution { public: int minDistRecur(string s1,string s2,int i,int j,vector<vector<int> >&memo){ if(i==1) return j+1; if(j==1) return i+1; if(memo[i][j]!=1) return memo[i][j]; memo[i][j]=min((s1[i]!=s2[j])+minDistRecur(s1,s2,i1,j1,memo),min(1+minDistRecur(s1,s2,i1,j,memo),1+minDistRecur(s1,s2,i,j1,memo))); return memo[i][j]; } int minDistance(string word1, string word2) { vector<vector<int> >memo(word1.length(), vector<int>(word2.length(),1)); return minDistRecur(word1,word2,word1.length()1,word2.length()1,memo); } };

RE: My Neat Solution in C++
The following code without reversing too slow (60 ms) because insert operation on vector that too at beginning will be too costly. I wonder if there's any other way that doesn't involve reversing or inserting at front.
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: void levelOrderBottomRecur(TreeNode *root, int level,vector<vector<int> > &result){ if(root==NULL) return; if(level>=result.size()) result.insert(result.begin(),vector<int>()); result[result.size()level1].push_back(root>val); levelOrderBottomRecur(root>left,level+1,result); levelOrderBottomRecur(root>right,level+1,result); } vector<vector<int>> levelOrderBottom(TreeNode* root) { vector<vector<int> > result; levelOrderBottomRecur(root,0,result); return result; } };

RE: Joker 4ms C++ solution using STL std::nth_element (quick select)
Mostly the purpose of this website is to prepare for the interview. Do you really think the interviewer is asking this problem to check if you remember the build in function?

RE: C++ inorder traversal, and please do not rely on buggy INT_MAX, INT_MIN solutions any more
Why rely on LLONG_MIN? Don't you think if you are in a true interview, the next question the interviewer will ask, "okay I have changed my input type to long" then? I am sorry but using long limit to such question is like taking shortcut to just get your answer accepted and won't help you in real interview.

RE: My C++ Trie + Backtrace based solution (48 ms)
I guess with new test cases the time the run time of this code got slightly increased to 52 ms. Mine is giving 48 ms still but got that after lot of hacks and optimizations.

Concise 0 ms c++ solution
class Solution { public: string convertToTitle(int n) { string s=""; while(n!=0){ char bit=('A'+((n1)%26)); s=bit+s; n=(n1)/26; } return s; } };