Asking someone if they need to talk means then I might have to listen to them and stuff.
I'm kidding - if someone is having a hard time and needs to talk, I'd pay attention. I just feel super uncomfortable trying to figure out what to say to make someone feel better, particularly somebody I don't know at all, so it would be really awkward. Hopefully I wouldn't make it worse. But yes, I would probably ask them if they are okay and if they need help, and I would do my best not to ruin everything.