If the value of seconds is less, you can use hash map (unordered_map in c++) to solve it in ~O(n) complexity.
Suppose you know that the maximum value of the pair is 600 secs, then you can have another array storing these values.
for(int i = 1; i <= 10; i++)
{
a[i-1] = i * 60;
}
//a[] = {60, 120, 180, 240, 300, 360, 420, 480, 540, 600};
unordered_map <int, int> mymap;
for(int i = 0; i < songs_count; i++)
{
mymap[i] = songs[i];
}
Now you can modify your code as (Solution is for C++):
long playlist(int songs_count, int *songs)
{
int i, j, k = 0;
for(int i = 1; i <= 10; i++)
{
a[i-1] = i * 60;
}
//a[] = {60, 120, 180, 240, 300, 360, 420, 480, 540, 600};
unordered_map <int, int> mymap;
for(int i = 0; i < songs_count; i++)
{
mymap[i] = songs[i];
}
for (i = 0; i < songs_count; i++)
{
for (j = 0; j < n /*size of a*/; j++)
{
if (a[j] > songs[i] && mymap.find(a[j] - songs[i]) != mymap.end())
{
k++;
}
}
}
return k;
}