2 ms·
that problem is a red hard problem so don't feel too bad but I don't understand your brute force solution? the brute force solution is the last step of merge so
by mlevental 8y ago
that problem is a red hard problem so don't feel too bad but I don't understand your brute force solution? the brute force solution is the last step of merge sort and then jumping to n//2
- HeyImJonathan 8y agoI think the OP was trying to accomplish the task without merging, so having a separate pointer for each array - with edge cases of differing array lengths?
- mlevental 8y agoyes that's much harder but not that's not what i would call the "brute force" solution so i'm not sure what they mean.
- Tmp1234 8y ago2 pointers, i and j, one for each array. I would have a while loop run for length of the arrays / 2 times. I would increment one of the pointers with each iteration based on which array had the next biggest number. When the while loop was done one of those pointers would be pointing the median if the length of both arrays summed to an odd number and I would return it. If the length was even, I would need to get the next biggest number from either array and average it with what would be the median if it was odd and then return that.