It seems to me that they had a lot of information about the office. Possibly they had simply been watching it for some time, or possibly they had someone on the inside or someone who had worked there and knew the routine.
According to a Swedish/French journalist who had been working with some of the victims the cartoonist did not usually spend their time at the Charlie Hebdo office, but convened there for editorial meetings only.
Were the terrorists lucky or did they know?
Anyway, their luck may soon have run out. According to a French newspaper the police have identified them......