Can you just briefly describe your algorithm and time complexity? Then we
could know the problem and think about from which perspective to improve it.

Thx!


2013/7/9 abhishek sharma <abhishek.p...@gmail.com>

>
>  Given *N* integers *A1, A2, .... AN*, Dexter wants to know how many ways
> he can choose three numbers such that they are three consecutive terms of
> an arithmetic progression.
>
> Meaning that, how many triplets *(i, j, k)* are there such that *1 ≤ i <
> j < k ≤ N* and *Aj - Ai = Ak - Aj*.
>
> So the triplets (2, 5, 8), (10, 8, 6), (3, 3, 3) are valid as they are
> three consecutive terms of an arithmetic progression. But the triplets (2,
> 5, 7), (10, 6, 8) are not.
> Input
>
> First line of the input contains an integer *N (3 ≤ N ≤ 100000)*. Then
> the following line contains *N* space separated integers *A1, A2, ..., AN*and 
> they have values between
> *1* and *30000* (inclusive).
> Output
>
> Output the number of ways to choose a triplet such that they are three
> consecutive terms of an arithmetic progression.
> Example
>
> *Input:*
> 10
> 3 5 3 6 3 4 10 4 5 2
> *Output:*
> 9
>
> *I am attaching my solution..* I reached this solution after improving the 
> performance 10 times.. but it is still not accepted as the time limit exceeds 
> 3 seconds.
>
> Can anyone please please suggest how to improve this ...
> (I do not want a different approach .. I want to improve my approach)
>
> PS: This is a practice problem .. So I am not cheating :)
>
>
> --
> Nice Day
>
> Abhishek Sharma
> Bachelor of Technology
> IIT Kanpur (2009)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to algogeeks+unsubscr...@googlegroups.com.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Reply via email to