My solution: DP + Rolling hash got TLE in Python :
@bufdud43 күн бұрын
Your python code still accepts, and actually faster than 70%...
@Krishnakantydv6 күн бұрын
i tried this N2 solutoin, 530 test case passes, it fails for input; [0,0,0,0,2,2,0,1,2,1,2], expected is 19, but my soluton returns 18. I cant even see the 19th split manually. Here is the code: class Solution { public: int beautifulSplits(vector& nums) { int n = nums.size(), count = 0; string total = ""; for (int i = 0; i < n; i++) { total += to_string(nums[i]); } for (int i = 0; i < n - 2; i++) { string str1 = total.substr(0, i + 1); // Check for match in the first intersection if (i 0) { count += k; } continue; // No need to check second joint for this `i` } } // Check for match in the second joint for (int size = 1; size
@Algorithmist5 күн бұрын
for small inputs, just run an N^3 solution and then compare your solution to it - so basically you are writing a verifier to help yourself debug