AP Class, Failing the exam

I took an AP class and got B’s in the class but failed the exam. Will that affect my chances of getting into a top school?

For a top school, let’s say top 20 in the US, we would want to aim for straight As. A few Bs may not impact the overall GPA in certain cases, but Bs shouldn’t be the aim. GPA is the most important part of an application, so it will be looked at most critically.

Are you referring to a teacher issued exam here or the official AP test?