Xor and Sum
Xor and Sum
+ 0 comments Here is Xor and Sum problem solution - https://programs.programmingoneonone.com/2021/07/hackerrank-xor-and-sum-problem-solution.html
+ 0 comments Testcases are to harmless!
Obviously (and annoyingly) this can be done without investing any brain power into DP solutions but instead just doing a direct calculation (see the next 2 discussion entries by davitkvarts and ydixit274).
+ 0 comments def xorAndSum(a, b):
a_len = len(a) a = int(a, 2) b = int(b, 2) p = (int)(1e9+7) res = 0 for i in range(a_len):#last is a_len res += (a^( b << i)) res %= 10**9+7 res += (a * (314160 - a_len)) % p res_2 = b * pow(2, a_len) * (pow(2, 314160-a_len,p)-1) return (res + res_2)%p
+ 0 comments def xorAndSum(a, b): a=int(a,2) b=int(b,2) sum=0 for i in range(314160): sum+=(a^(b<<i)) return sum %1000000007
+ 0 comments Is this realistic for those that are not comming from a mathematics background?
I'm curious.... Reason is, a good number of people who want to learn to code typically don't come from a mathematics heavy background. This question feels like a gatekeeper for a lot of people. I would love it if it was possible to revoke qustions like theses. No matter the difficulty, pure maths is pure maths. Computer science is computer science. Algorithms are algorithms. Physics is physics. Engineering is engineering.
Sort 51 Discussions, By:
Please Login in order to post a comment