Thank you everyone, i some how able to solve this.
I did it by finding the count of unique A1's and i stored it in hash as a key, A loop to iterate that many number of times to create a new hash which store the A1 and activedate as a key.
Sort by active date
find the consecutive rows by having a count(unique A1 and B1).