  C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD # Code to find out the number of triplets which lead to a sum less than or equal to threshold is giving a wrong output

## Code to find out the number of triplets which lead to a sum less than or equal to threshold is giving a wrong output Tag : cpp , By : Porta Date : November 24 2020, 05:44 AM

I wish did fix the issue. Every element of nums is greater equal zero.
Therfor a = nums[i] is greater equal zero.
``````if(a > 0) break;
``````
``````if(a > threshold) break;
`````` Boards Message : You Must Login Or Sign Up to Add Your Comments .

## Array.equal() giving wrong output

Tag : java , By : Daniel Halsey
Date : March 29 2020, 07:55 AM
To fix the issue you can do This has nothing to do with arrays really. Your comparison is equivalent to:
``````Object x = Integer.valueOf(3);
Object y = Byte.valueOf((byte) 3);
boolean equal = x.equals(y);
``````

## Program to find trailing number of zeroes is giving wrong output

Tag : c , By : unfool
Date : March 29 2020, 07:55 AM
To fix the issue you can do You're never initializing number, and then you're printing a pointer to it instead of the number itself. Of course you're going to print garbage results.
Also, I don't understand how your algorithm is supposed to work. Dividing by five and adding that to the number of zeroes? If I did that with the number 100, that would add 20, but 100 doesn't have 20 trailing zeroes.

## Find the number of triplets i,j,k in an array such that the xor of elements indexed i to j-1 is equal to the xor of elem

Tag : arrays , By : Giles
Date : March 29 2020, 07:55 AM
will help you Here's an O(n) solution based on CiaPan's comment under the question description:
``````import random

def brute_force(A):
res = 0

for i in xrange(len(A) - 1):
left = A[i]
for j in xrange(i + 1, len(A)):
if j > i + 1:
left ^= A[j - 1]
right = A[j]
for k in xrange(j, len(A)):
if k > j:
right ^= A[k]
if left == right:
res += 1

return res

def f(A):
ps = [A] +  * (len(A) - 1)
for i in xrange(1, len(A)):
ps[i] = ps[i- 1] ^ A[i]

res = 0
seen = {0: (-1, 1, 0)}

for  i in xrange(len(A)):
if ps[i] in seen:
prev_i, i_count, count = seen[ps[i]]
new_count = count + i_count * (i - prev_i) - 1
res += new_count
seen[ps[i]] = (i, i_count + 1, new_count)
else:
seen[ps[i]] = (i, 1, 0)

return res

for i in xrange(100):
A = [random.randint(1, 10) for x in xrange(200)]
f_A, brute_force_A = f(A), brute_force(A)
assert f_A == brute_force_A
print "Done"
``````

## Find ways an Integer can be expressed as sum of n-th power of unique natural numbers.code giving wrong output

Tag : cpp , By : Peter Leung
Date : March 29 2020, 07:55 AM
I wish this helpful for you I inserted a simple debug output in func. For the given input "1 10 2" x sometimes gets negative. This causes UB when accessing the array, but does not necessarily crash.
You already check if x is less than 0, but after using x. Move the if(x < 0) up and you are done.

## Find the total number of triplets when summed are less than a given threshold

Tag : python , By : cynix
Date : March 29 2020, 07:55 AM 