Why are these two codes behaving differently only difference in the two is the way freq is stored (line 14)
I see that in one solution you use ‘% mod’ frequently, while in the other you do not. Without looking in detail, I suggest that when you don’t use ‘% mod’ at every step you soon have an overflow.
1 Like
mod of freq before sorting will give wa.
for i, j node,
if(freq[i] > freq[j]) node i should be assign larger value or equal value as node j;
freq[i] % mod < freq[j] % mod , it is quite possible (that is giving the WA verdict).