id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string text1, string text2) {\n int m = text1.size();\n int n = text2.size();\n\n // Brute-force n^2 approach -> getting TLE\n // vector<vector<int>> dp(m+1, vector<int>(n+1, 0));\n\n // for(int i=1; i<=m; i++){\...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string text1, string text2) {\n int m = text1.size();\n int n = text2.size();\n\n // Brute-force n^2 approach -> getting TLE\n // vector<vector<int>> dp(m+1, vector<int>(n+1, 0));\n\n // for(int i=1; i<=m; i++){\...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int solve(int ind1, int ind2, string text1, string text2,\n vector<vector<int>>& dp) {\n if (ind1 == 0 || ind2 == 0)\n return 0;\n if (dp[ind1][ind2] != -1)\n return dp[ind1][ind2];\n if (text1[ind1 - 1] == text2[ind2 - ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string text1, string text2) {\n int n = text1.size();\n int m = text2.size();\n if(text1==text2) return text1.size();\n vector<int> dp1(m+1,0);\n for(int i = 1; i<=n; i++){\n vector<int> dp2(m+1,0);\n ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int solve(int ind1, int ind2, string text1, string text2,\n vector<vector<int>>& dp) {\n if (ind1 == 0 || ind2 == 0)\n return 0;\n if (dp[ind1][ind2] != -1)\n return dp[ind1][ind2];\n if (text1[ind1 - 1] == text2[ind2 - ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int solve(int i, int j, string s1, string s2,vector<vector<int>> &dp){\n if(i == 0 or j == 0) return 0;\n if(dp[i][j] != -1) return dp[i][j];\n\n if(s1[i-1] == s2[j-1]){\n return dp[i][j] = 1 + solve(i-1,j-1,s1,s2,dp);\n }else{\n ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int solve(int ind1, int ind2, string text1, string text2,\n vector<vector<int>>& dp) {\n if (ind1 == 0 || ind2 == 0)\n return 0;\n if (dp[ind1][ind2] != -1)\n return dp[ind1][ind2];\n if (text1[ind1 - 1] == text2[ind2 - ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string text1, string text2) {\n if(text1==text2) return text1.size();\n int n=text1.size(), m=text2.size();\n vector<vector<int>> dp(n+1,vector<int>(m+1,0));\n int ans=0;\n for(int i=1; i<=n; i++){\n ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int maxCommon(int ind1, int ind2, string& str1, string& str2, vector<vector<int>>& dp){\n if(ind1 < 0 || ind2 < 0)\n return 0;\n\n if(dp[ind1][ind2] != -1)\n return dp[ind1][ind2];\n\n if(str1[ind1] == str2[ind2])\n return...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\n int f(int i1, int i2, string &s1, string &s2, vector<vector<int>>& dp) {\n if(i1>=s1.size() || i2>=s2.size()) return 0;\n if(dp[i1][i2]!=-1){\n return dp[i1][i2];\n }\n int a=f(i1,i2+1,s1,s2,dp);\n a=max(a,f(i1+1,i2,s1,s2,dp));\n if...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\n vector<int> memo;\n int memoStride;\n \n void memoReset(int size1, int size2) {\n memoStride = size1 + 1;\n memo.resize((size1 + 1) * (size2 + 1), -1);\n }\n int memoSet(int size1, int size2, int value) { return memo[memoStride * size2 + size1] = value;...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\n vector<int> memo;\n int memoStride;\n \n void memoReset(int size1, int size2) {\n memoStride = size1 + 1;\n memo.resize((size1 + 1) * (size2 + 1), -1);\n }\n int memoSet(int size1, int size2, int value) { return memo[memoStride * size2 + size1] = value;...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\n vector<int> memo;\n int memoStride;\n \n void memoReset(int size1, int size2) {\n memoStride = size1 + 1;\n memo.resize((size1 + 1) * (size2 + 1), -1);\n }\n int memoSet(int size1, int size2, int value) { return memo[memoStride * size2 + size1] = value;...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\n int f[2000][2000];\npublic:\n int longestCommonSubsequence(string text1, string text2) {\n int n=text1.length();\n int m=text2.length();\n for(int i=1;i<=n;i++){\n for(int j=1;j<=m;j++){\n if(text1[i-1]==text2[j-1]){\n ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int dp[2000][2000];\n \n int longestCommonSubsequence(string text1, string text2) {\n int m = text1.length();\n int n = text2.length();\n memset(dp, 0, sizeof(dp));\n\n for (int i = 1; i <= m; i++) {\n for (int j = 1; j <= n; j++) ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string text1, string text2) {\n int l2=text2.length();\n int l1=text1.length();\n\n vector<int> dp(l2+1,0);\n for(int i=0;i<l1;i++)\n {\n vector<int> cur(l2+1,0);\n for(int j=1;j<=l2;j++)\n ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string text1, string text2) {\n int n=text1.size();\n int m = text2.size();\n if(m<n){\n string temps =text1;\n text1=text2;\n text2=temps;\n }\n n=text1.size();\n m =...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string text1, string text2) {\n int n = text1.size();\n int m = text2.size();\n vector<int>prev(m+1,-1);\n\n for(int j=0;j<=m;j++) prev[j] = 0;\n\n for(int i=1;i<=n;i++){\n vector<int>curr(m+1,-1);\n ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int helper(int i, int j, string s1, string s2, vector<vector<int>>& dp)\n {\n if(i == 0 || j == 0) return 0;\n\n if(dp[i][j] != -1) return dp[i][j];\n\n if(s1[i-1] == s2[j-1]) return dp[i][j] = 1 + helper(i-1, j-1, s1, s2, dp);\n return dp[i][j]...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string text1, string text2) {\n int m = text1.size();\n int n = text2.size();\n\n vector<int> dp(n+1, 0);\n for(int i=1;i<=m;i++)\n {\n vector<int> temp(n+1, 0);\n for(int j=1;j<=n;j++)\n ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "class Solution {\npublic:\n \n int solveUsingRecursion(string a, string b, int i, int j){\n //base case\n if(i==a.length()) return 0;\n if(j==b.length()) return 0;\n\n int ans = 0;\n if(a[i]==b[j]) return 1 + solveUsingRecursion(a, b, i+1, j+1);\n else{\n ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
0
{ "code": "/*\n Given 2 strings, return length of longest common subsequence\n Ex. text1 = \"abcde\", text2 = \"ace\" -> 3, \"ace\" is LCS\n\n j\n a c e\n a 3\n b 2 --> visualization of below, build DP bottom-up\n i c 2\n d 1\n ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
1
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string text1, string text2) {\n\n vector<vector<int>> grid(text1.size(),vector<int>(text2.size(),0));\n for (int i=0;i<text1.size();i++)\n {\n for (int j=0;j<text2.size();j++)\n {\n int x=0...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
1
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string text1, string text2) {\n int n = text1.length();\n int m = text2.length();\n // abcde ace\n vector<vector<int>>dp(n+1,vector<int>(m+1,0));\n\n for(int i = 1;i<=n;i++){\n for(int j=1;j<=m;j++)...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
1
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string text1, string text2) {\n int m = text1.size();\n int n = text2.size();\n vector<vector<int>> dp(m + 1, vector<int>(n + 1, 0));\n\n for (int i = 1; i <= m; ++i) {\n for (int j = 1; j <= n; ++j) {\n ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
1
{ "code": "class Solution {\npublic:\n int longestCommonSubsequence(string text1, string text2) {\n int len1=text1.length();\n int len2=text2.length();\n vector<vector<int>>dp(len1+1,vector<int>(len2+1,0));\n //int dp[][]= new int dp[len1+1][len2+1];\n for(int i=1;i<=len1;i++)\n ...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
2
{ "code": "class Solution {\npublic:\n int helper(vector<vector<int>>& dp, int i, int j, string& text1,\n string& text2) {\n if (i == text1.size() || j == text2.size()) {\n return 0;\n }\n if (dp[i][j] != -1) {\n return dp[i][j];\n }\n int take...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
2
{ "code": "class Solution {\n private:\n int f(int j1,int j2,string &t1,string &t2,vector<vector<int>>&dp){\n if(j1<0||j2<0)return 0;\n if(dp[j1][j2]!=-1)return dp[j1][j2];\n if(t1[j1]==t2[j2]){\n return 1+f(j1-1,j2-1,t1,t2,dp);\n }\n return dp[j1][j2] = max(f(j...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
3
{ "code": "// Longest Common Subsequence\n// given two strings s1 and s2, find length of LCS\n// start at end of both strings, if match 1 + [move, move]\n// else 0 + max([move, stay], [stay, move])\n\n// // Recursion\n// // f(i,j) : length of LCS in s1[0,1,2,...i] and s2[0,1,2,...j]\n// class Solution {\n// public:\n...
1,250
<p>Given two strings <code>text1</code> and <code>text2</code>, return <em>the length of their longest <strong>common subsequence</strong>. </em>If there is no <strong>common subsequence</strong>, return <code>0</code>.</p> <p>A <strong>subsequence</strong> of a string is a new string generated from the original strin...
3
{ "code": "class Solution {\nprivate:\nint dp(int ind1, int ind2, string &t1, string &t2, vector<vector<int>> &cache) {\n if (ind1 < 0 || ind2 < 0) {\n return 0;\n }\n if (cache[ind1][ind2] != -1) {\n return cache[ind1][ind2];\n }\n\n if (t1[ind1] == t2[ind2]) {\n cache[ind1][ind2]...
292
<p>You are playing the following Nim Game with your friend:</p> <ul> <li>Initially, there is a heap of stones on the table.</li> <li>You and your friend will alternate taking turns, and <strong>you go first</strong>.</li> <li>On each turn, the person whose turn it is will remove 1 to 3 stones from the heap.</li> <...
0
{ "code": "class Solution {\npublic:\n bool canWinNim(int n) {\n if(n%4==0){\n return false;\n }\n else return true;\n }\n};", "memory": "7000" }
292
<p>You are playing the following Nim Game with your friend:</p> <ul> <li>Initially, there is a heap of stones on the table.</li> <li>You and your friend will alternate taking turns, and <strong>you go first</strong>.</li> <li>On each turn, the person whose turn it is will remove 1 to 3 stones from the heap.</li> <...
0
{ "code": "class Solution {\npublic:\n bool canWinNim(int n) {\n if(n%4==0){\n return false;\n }else{\n return true;\n }\n }\n};", "memory": "7100" }
292
<p>You are playing the following Nim Game with your friend:</p> <ul> <li>Initially, there is a heap of stones on the table.</li> <li>You and your friend will alternate taking turns, and <strong>you go first</strong>.</li> <li>On each turn, the person whose turn it is will remove 1 to 3 stones from the heap.</li> <...
0
{ "code": "class Solution {\npublic:\n bool canWinNim(int n) {\n \n if(n%4==0){\n return false;\n }\n else{\n return true;\n }\n }\n};", "memory": "7100" }
292
<p>You are playing the following Nim Game with your friend:</p> <ul> <li>Initially, there is a heap of stones on the table.</li> <li>You and your friend will alternate taking turns, and <strong>you go first</strong>.</li> <li>On each turn, the person whose turn it is will remove 1 to 3 stones from the heap.</li> <...
0
{ "code": "class Solution {\npublic:\n bool canWinNim(int n) {\n if(n%4==0){\n return false;\n }\n return true;\n }\n};", "memory": "7200" }
292
<p>You are playing the following Nim Game with your friend:</p> <ul> <li>Initially, there is a heap of stones on the table.</li> <li>You and your friend will alternate taking turns, and <strong>you go first</strong>.</li> <li>On each turn, the person whose turn it is will remove 1 to 3 stones from the heap.</li> <...
0
{ "code": "class Solution {\n public:\n bool canWinNim(int& n) {\n return n % 4;\n }\n};", "memory": "7200" }
292
<p>You are playing the following Nim Game with your friend:</p> <ul> <li>Initially, there is a heap of stones on the table.</li> <li>You and your friend will alternate taking turns, and <strong>you go first</strong>.</li> <li>On each turn, the person whose turn it is will remove 1 to 3 stones from the heap.</li> <...
0
{ "code": "class Solution {\npublic:\n bool canWinNim(int n) {\n if(n%4==0){\n return false;\n }else{\n return true;\n }\n }\n};", "memory": "7300" }
292
<p>You are playing the following Nim Game with your friend:</p> <ul> <li>Initially, there is a heap of stones on the table.</li> <li>You and your friend will alternate taking turns, and <strong>you go first</strong>.</li> <li>On each turn, the person whose turn it is will remove 1 to 3 stones from the heap.</li> <...
0
{ "code": "class Solution {\npublic:\n bool canWinNim(int n) {\n return n % (4);\n }\n};", "memory": "7300" }
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
0
{ "code": " class Solution {\npublic:\n string getHint(string secret, string guess) {\n int bulls = 0, cows = 0;\n vector<int>countSecret(10,0);\n vector<int>countGuess(10,0); \n\n \n for (int i = 0; i < secret.size(); i++) {\n if (secret[i] == guess[i]) {\n ...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
0
{ "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n array<int, 10> counts;\n int bulls = 0;\n for (int i = 0; i < secret.size(); ++i) {\n if (secret[i] == guess[i])\n bulls++;\n else\n counts[secret[i] - '0'...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
0
{ "code": "class Solution {\n public:\n string getHint(string secret, string guess) {\n int A = 0;\n int B = 0;\n vector<int> count1(10);\n vector<int> count2(10);\n\n for (int i = 0; i < secret.length(); ++i)\n if (secret[i] == guess[i])\n ++A;\n else {\n ++count1[secret[i] - ...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
0
{ "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n int cow=0;\n vector<int>v1(10,0);\n vector<int>v2(10,0);\n for(int i=0;i<secret.length();i++){\n v1[secret[i]-'0']++;\n }\n for(int i=0;i<guess.length();i++){\n v2[...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
0
{ "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n int n = secret.length();\n int a = 0, b = 0;\n vector<int> secret_count(10, 0), guess_count(10, 0); \n\n for (int i = 0; i < n; i++) {\n if (secret[i] == guess[i]) {\n a++; ...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
0
{ "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n int a=0,b=0;\n for(int i=0;i<secret.size();i++){\n if(secret[i]==guess[i]){\n secret[i]='b';\n guess[i]='b';\n b++;\n }\n }\n\n for(i...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
0
{ "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n int bulls=0,cows=0;\n vector<int>secretCount(10, 0); \n vector<int>guessCount(10, 0);\n for (int i=0;i<secret.length();++i) {\n if (secret[i]==guess[i]) {\n bulls++;\n ...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
0
{ "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n vector<int> v(10,0);\n int x=0;\n for(int i=0;i<secret.size();i++){\n if(secret[i]==guess[i]) x++;\n else v[secret[i]-'0']++;\n }\n int y=0;\n for(int i=0;i<guess.s...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
1
{ "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n vector<int> v1(10,0);\n vector<int> v2(10,0);\n int n = secret.length();\n for(int i=0;i<n;i++){\n int x = secret[i] - '0';\n int y = guess[i] - '0';\n v1[x]++;\n ...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
1
{ "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n \n int bulls = 0; // Count of bulls\n int cows = 0; // Count of cows\n \n // Frequency arrays for digits 0-9\n vector<int> s(10, 0); // Frequency of digits in secret\n vector<...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
1
{ "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n vector<int> digitAt((int)secret.size());\n vector<int> digitFreq(10);\n\n int bulls = 0, cows = 0;\n\n for(int i = 0; i < secret.length(); i++) {\n digitFreq[secret[i] - '0']++;\n ...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
1
{ "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n int m[256] = {0}, bulls = 0, cows = 0;\n for (int i = 0; i < secret.size(); ++i) {\n if (secret[i] == guess[i]) ++bulls;\n else ++m[secret[i]];\n }\n for (int i = 0; i < secret.s...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
1
{ "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n int start = 0;\n int bulls = 0;\n int cows = 0;\n vector<int> map(256, 0);\n vector<int> count;\n for(const auto & val: secret){\n if(val == guess[start]){\n ++...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
1
{ "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n \n vector<int> dict(10,0);\n int n = secret.size();\n vector<int> possible_B_index;\n for(int i = 0; i < n; i++){\n if(secret[i]!=guess[i]){\n possible_B_index.push_ba...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
1
{ "code": "class Solution {\npublic:\n \n string getHint(string secret, string guess) {\n int bulls = 0;\n vector<int>freqs(300, 0), freqg(300, 0);\n for (int i = 0; i < secret.size(); i++) {\n if (secret[i] == guess[i]) {\n bulls++;\n }else {\n ...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
1
{ "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n int count_a = 0;\n int count_b = 0;\n int arr_secret[10] = {0};\n int arr_guess[10] = {0};\n int i = 0;\n \n for (i = 0; i < secret.length(); i++) {\n if (secret[i] == ...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
1
{ "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n int bulls = 0;\n int cows = 0;\n\n std::unordered_map<char, int> lookFor;\n std::unordered_set<int> skip;\n for(int i = 0; i < secret.size(); ++i)\n {\n if(secret[i] == guess[...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
1
{ "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n \n int bullscnt = 0;\n\n unordered_map<char, int> mapcnt;\n\n for (int i = 0; i < guess.size(); i++)\n {\n if (guess [i] == secret [i])\n {\n bullscnt++;\n ...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
1
{ "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n unordered_map<char,int> secretMap;\n int bulls = 0;\n int cows = 0;\n for(auto i:secret) {\n secretMap[i] += 1;\n }\n int iter = 0;\n for(auto i:guess) {\n i...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
1
{ "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n int bulls = 0, cows = 0;\n unordered_map<char, int> secretMap, guessMap;\n for (int i = 0; i < secret.size(); i++) {\n if (secret[i] == guess[i]) {\n bulls++;\n } else {\...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
1
{ "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n unordered_map<char,int>mp;\n int cnt = 0;\n for(int i = 0; i < secret.size(); i++){\n if(secret[i] == guess[i]) cnt++;\n else mp[secret[i]]++;\n }\n string ans = \"\";\n ...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
2
{ "code": "#include <string> \n#include <unordered_map> \nusing namespace std; \n\nclass Solution { \npublic: \n string getHint(string secret, string guess) { \n int bulls = 0; // Count of correct digits in the correct position \n int cows = 0; // Count of correct digits in the wrong position...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
2
{ "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n unordered_map<int,int> dict;\n for (int i = 0;i < secret.size(); i++) {\n dict[secret[i]]++;\n }\n int bulls = 0;\n for (int i = 0;i < secret.size(); i++) {\n if (secret[i...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
2
{ "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n int n = secret.length();\n map<char,int> mp;\n for(int i=0 ; i<n ; ++i) mp[secret[i]]++;\n int bulls = 0;\n int cows = 0;\n for(int i=0 ; i<n ; ++i){\n if(secret[i] == guess[...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
2
{ "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n int x=0;\n int y=0;\n map<int,int> mp;\n\n for(int i=0;i<secret.size();i++){ \n mp[secret[i]]++;\n }\n\n\n for(int i=0;i<guess.size();i++){\n if(secret[i]==guess[i]...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
3
{ "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n int b = 0, c = 0;\n map <char, int> m;\n map <char, int> matched;\n for (auto &x : secret)\n m[x]++;\n\n for (int i = 0; i < secret.size(); i++) {\n if (secret[i] == guess...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
3
{ "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n int a=0,b=0;\n map<char,int> ms,mg;\n for(int i=0; i<guess.size();i++){\n if(secret[i]==guess[i]) a++;\n else{\n ms[secret[i]]++;\n mg[guess[i]]++;\n ...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
3
{ "code": "class Solution {\npublic:\n string getHint(string s, string g) {\n int b = 0 ;\n int n = s.size();\n map<char , int>m1;\n map<char , int>m2;\n for(int i =0;i<n;i++)\n {\n if(s[i] == g[i])b++;\n m1[s[i]]++;\n m2[g[i]]++;\n ...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
3
{ "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n unordered_map<char, int> m;\n unordered_set<int> s;\n int cows = 0, bulls = 0;\n for(int i = 0; i < secret.length(); i++){\n m[secret[i]]++;\n }\n for(int i = 0; i < secret.le...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
3
{ "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n // string res = \"0A0B\";\n int bulls = 0;\n int cows = 0;\n\n map<int, int> st;\n set<int> vis;\n\n for (int i = 0; i < guess.size(); i++) {\n if (secret[i] == guess[i]) {\n ...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
3
{ "code": "class Solution {\npublic:\n string getHint(string secret, string guess) {\n int n=secret.size();\n int count=0;\n set<int>s;\n\n for(int i=0;i<n;i++)\n {\n if(secret[i]==guess[i])\n { \n count++; s.insert(i);\n }\n }\n ...
299
<p>You are playing the <strong><a href="https://en.wikipedia.org/wiki/Bulls_and_Cows" target="_blank">Bulls and Cows</a></strong> game with your friend.</p> <p>You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info:</p>...
3
{ "code": "class Solution {\npublic:\n\n string exclude(string code, int n)\n {\n if(n>code.length()-1)\n return code;\n \n string output=\"\";\n if(!(n==0))\n {\n output=code.substr(0,n);\n \n if(n<code.length()-1)\n {\n output=ou...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
0
{ "code": "#include <vector>\n#include <algorithm>\n\nusing namespace std;\n\n// Using Binary Search [O(n log n), O(n)]\nclass Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n int n = nums.size();\n\n if (n == 0) return 0;\n\n vector<int> lis;\n\n for (auto num : nums) {\n ...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
0
{ "code": "class Solution {\n \npublic:\n\n \n int lengthOfLIS(vector<int>& nums) {\n \n \n int n=nums.size();\n // vector<vector<int>> dp(n,vector<int>(n+1,-1));\n\n //return len(nums,0,-1,n,dp);\n vector<int> temp;\n temp.push_back(nums[0]);\n for(int i=1;i...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n if (nums.size() <=1){\n return nums.size();\n }\n map<int, int> solution; // val->length {7, 1}\n solution[nums[0]] = 1;\n for(int i=1; i<nums.size(); ++i) {\n int key = nums[i];\...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n\n if (nums.size() == 0) {\n return 0;\n }\n \n int ans = 1;\n map<int, int> hashmap;\n for(int i =0;i < nums.size();i++) {\n ans = max(ans, helper(nums, i, hashmap));\n ...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "\nclass Solution {\npublic:\n int binarySearch(vector<int> vec, int num)\n {\n int l = 0;\n int r = vec.size() - 1;\n int mid = (l + r)/2;\n int pos = -1;\n while(r >= l)\n {\n mid = (l+r)/2;\n if(num > vec[mid]) l = mid + 1;\n ...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n vector<int> result;\n for (int i : nums) {\n if (result.empty() || i > result.back()) {\n result.push_back(i);\n } else {\n int index = find(result, i);\n r...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "#define LIMIT 1e4+1\nclass Solution {\n int util(int i, int prev, vector<int>& nums, vector<vector<int>> & dp){\n // cout << i << \", \" << prev << \"\\n\";\n if(i == nums.size()){\n return 0;\n }\n if(dp[i][prev + LIMIT] !=-1 ){\n return dp[i][prev + LI...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "#include<bits/stdc++.h>\nclass Solution {\npublic:\n int solve(vector<int>& nums, vector<vector<int>> &dp, int i, int maxm) {\n if(i == nums.size()) {\n dp[i][maxm + 10001] = 0;\n return 0;\n }\n \n if(dp[i][maxm + 10001] != -1) {\n return dp[...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "struct SegTree {\n vector<int> tree;\n int n;\n\n SegTree(int n) : n(n) {\n tree = vector<int>(n*2);\n }\n\n void update(int idx, int val) {\n idx += n;\n tree[idx] = max(val, tree[idx]);\n for (idx >>= 1; idx >= 1; idx >>= 1) {\n tree[idx] = max(tree[i...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "// Segment tree Sum\n class ST {\n \tint n;\n \tvector<int> tree;\n public:\n \tST(const vector<int>& data) {\n \t\tint N = data.size();\n \t\tn = N;\n \t\ttree.resize(2 * n);\n \t\tfor (int i = 0; i < n; i++) {\n \t\t\ttree[i + n] = data[i];\n \t\t}\n \t\tbuild();\n ...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "class Solution {\npublic:\n #define offset int(10000)\n class SegmentTree {\n private:\n vector<int> seg;\n public:\n SegmentTree() {\n seg = vector<int> (8 * offset + 10, 0);\n }\n void update(int i, int l, int r, int node, int...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "\n\nclass Solution {\npublic:\n int dp[5000000];\n int lis(int i, vector<int>&a){\n if (dp[i] != -1){\n return dp[i];\n }\n int ans =1;\n for (int j=0; j<i; j++){\n if (a[i]>a[j]){\n ans = max(ans,lis(j,a)+1);\n }\n }\n return dp[i] = ans;\n }\n\n int le...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n int n = nums.size();\n vector<int> seq;\n seq.push_back(nums.at(0));\n\n auto lowerbound = [&](vector<int> arr , int a ){\n int n = arr.size(); \n int l = 0 , r = n - 1 ;\n whi...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n vector<int> vec;\n for(int i=0;i<nums.size();i++) {\n int x = nums[i];\n if (i==0) {\n vec.push_back(x);\n } else {\n int pos = search(vec, x);\n ...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "int t[2501][2501];\nclass Solution {\npublic:\n\n int solve(vector<int>& nums, int n, int index){\n if(n==nums.size()) return 0;\n if(t[n][index+1]!=-1) return t[n][index+1];\n int notInclude=solve(nums, n+1, index);\n int include=0;\n if(index==-1 || nums[n]>nums[inde...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "vector<int> numList;\nconst int MAX = 2500 + 1;\nint memory[MAX][MAX];\n\n// called with LIS(0, m)\nint LIS(int i, int prev) {\n if (i == numList.size())\n return 0;\n\n auto& ret = memory[i][prev];\n\n if (ret != -1)\n return ret;\n\n int leave = LIS(i + 1, prev);\n int take =...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "class Solution {\npublic:\n \n vector<int> nums;\n int dp[2509][2509];\n int go(int idx, int preIdx) {\n\n if (idx == nums.size()) return 0;\n\n if (dp[idx][preIdx + 1] != -1) \n return dp[idx][preIdx + 1];\n \n int take = 0, notTake = 0;\n\n if (pr...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "class Solution {\npublic:\n int dp[2502][2502];\n int func(int idx, int prev, vector<int>& nums){\n int n=nums.size();\n if(idx>=n) return 0;\n if(dp[idx][prev]!=-1) return dp[idx][prev];\n int x=0;\n for(int i=idx; i<n; i++){\n if(nums[prev] < nums[i]){\...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "class Solution {\npublic:\n\n int find_position(vector<int> arr,int num,int start,int end){\n // i want to find the index of first element greater than or equal to num\n\n if(start == end){\n return start;\n }\n int mid = (start+end)/2;\n if(arr[mid]==num ||...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "class Solution {\npublic:\n int dp[2501][2501];\n bool checkdp[2501][2501];\n \n int rec(int level, int prev_idx, vector<int>&nums) {\n int n = nums.size();\n // pruning case\n if (level >= n) return 0;\n // cache check\n if (checkdp[level][prev_idx + 1]) retu...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "class Solution {\npublic:\n int dp[3000][3000];\n int f(int i, int prev, vector<int>& nums) {\n if (i < 0) {\n return 0;\n }\n if (dp[i][prev+1]!=-1) {\n return dp[i][prev+1];\n }\n int take = -1e8;\n int not_take = f(i - 1, prev, nums);...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "class Solution {\npublic:\n int dp[3000][3000];\n int func(vector<int>& nums, int prev,int idx,int len){\n if(idx == nums.size()){\n return 0;\n }\n if(dp[prev][idx] != -1) return dp[prev][idx];\n int ans = 0;\n if(nums[idx]>nums[prev]){\n ans...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "class Solution {\npublic:\n int n;\n int dp[3000][3000];\n int rec(int i, int pre, vector<int>& nums){\n if(i==n) return 0;\n if(dp[i][pre+1] != -1) return dp[i][pre+1];\n int ans = rec(i+1,pre,nums);\n if(pre==-1 || nums[pre] < nums[i]){\n ans = max(ans, 1+r...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "class Solution {\npublic:\n \nint binary(vector<int> arr,int left,int right,int target)\n {\n cout<<left<<' '<<right<<\"\\n\";\n if(right>=left)\n {\n int mid = left + (right-left)/2;\n \n if(arr[mid]==target){return mid;}\n else if(arr...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "#define ll long long int\nll n;\nll dp[2501][2501];\nll a[2501];\nclass Solution {\npublic:\n ll solve(ll i,ll st){\n if(i>=n)return 0;\n if(dp[i][st+1]!=-1&&st!=-1){\n return dp[i][st+1];\n }\n ll ans=0;\n if(st==-1||(st!=-1&&a[st]<a[i])){\n ans=max(ans,solve(i+1,i)+1);\n ...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "#define ll long long\nll a[2505];\nll dp[2505][2505];\nint n;\n\nll func(int age, int akhon)\n{\n if(akhon>n){\n return 0;\n }\n if(dp[age][akhon]!=-1) return dp[age][akhon];\n // nibo\n ll ans=0;\n if(a[akhon]>a[age])\n {\n ans=1+func(akhon, akhon+1);\n }\n // nibo...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "class Solution {\npublic:\n long long dp[2502][2502];\n long long solve(vector<int> &nums, int pos, int prev_ind) {\n int n = nums.size();\n if(pos >= n) return 0;\n //to handle prev_ind = -1 we are using 2501 for prev_ind\n if(prev_ind == -1) {\n if(dp[pos][250...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "class Solution {\npublic:\n long dp[2501][2501];\n int n; \n \n int solve(vector<int>& nums, int i, int p){\n if(i >= n)\n return 0;\n \n if(p!=-1 && dp[i][p] != -1)\n return dp[i][p];\n \n int take = 0;\n if(p == -1 || nums[p] < ...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "class Solution {\n static void logArray(ostream& s, const vector<int> v) {\n s << \"[\";\n for (auto i : v) {\n s << i << \" \";\n }\n s << \"]\" << endl;\n }\npublic:\n int lengthOfLIS(vector<int>& nums) {\n const size_t size = nums.size();\n l...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "class Solution {\npublic:\n int lengthOfLIS(vector<int>& nums) {\n vector <int> dp(nums.size(), -1);\n vector <vector <int> > lis(nums.size(), vector<int>());\n \n int j = 1;\n\n dp[0] = nums[0];\n vector <int> v;\n v.push_back(nums[0]);\n lis[0] =...
300
<p>Given an integer array <code>nums</code>, return <em>the length of the longest <strong>strictly increasing </strong></em><span data-keyword="subsequence-array"><em><strong>subsequence</strong></em></span>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <pre> <strong>Input:</strong> nums = [10...
2
{ "code": "class Solution {\npublic:\n int lengthOfLIS(std::vector<int> &nums) {\n std::vector<int> dp(nums.size());\n auto comparator = [&nums](int a, int b) { return nums[a] > nums[b]; };\n\n std::priority_queue<int, std::vector<int>, decltype(comparator)> pq(\n comparator);\n\n ...