vendredi 3 avril 2020

how to find the number of contiguous subsequences whose product can be expressed as difference of squares of 2 random integers?

So,let's suppose the given sequence is {2,1,3,4}.The contiguous subsequences that'd satisfy the question's condition will be {1},{3},{4},{1,3},{1,3,4},{3,4},{2,1,3,4}. Therefore the total number of contiguous subsequences are 7.

My Approach:-I did a little math and found out that all the numbers which are odd or the numbers which are divisible by 4 will satisfy the question's condition.But when i try to write the program it takes O(n2) in worst case as i check for each contiguous subsequence.Can u help me on how to come up with an optimized approach?

Aucun commentaire:

Enregistrer un commentaire