Mechanics of reasoning during programming interviews [closed]

This is not the usual “I don’t want to write code during an interview”, in this question the assumption is that

  • I need to write code during an interview (think about the level of rewriting the quicksort or mergesort from scratch)
  • I know how the algorithm work or I have a basic idea of how I should start working from there, i.e. I don’t remember the algorithm by heart

I noticed that even on a whiteboard, I always end up writing bugged code or code that doesn’t compile. If there’s a typo, whatever I usually live with that.. but when there’s a crash due to some uncaught particular case I end up losing confidence in my skills.

I realize that perhaps interviewers might want to look at how I write code and/or how I solve problems rather than proof-compiling my whiteboard code, but I’d like to ask how should I approach the above problem in mental terms, i.e. what mental steps should I follow when writing code for an interview with the two bullet points above.

There must be a unique and agreed series of steps I should follow to avoid getting stuck/caught into particular exception cases (limit cases) that might end up wasting my time and my energies rather than focusing on the overall algorithm for the general case.

I hope I made my point clear

3

If I were asked to write code for a problem that I thought was particularly finicky or had edge-case complications, I would definitely write notes on the board first. For a simple example, let’s say I was asked to write the method Arrays.toString(int[] array) in Java. I would write, on the board, something like:

  • If the input is null, return "null"
  • If the input is an empty array, return "[]"
  • Otherwise, I must:
    • Output a "[" for the first element
    • Output a "]" for the last element
    • Output a ", " between elements
    • If there is exactly one element, don’t print a ", ".

Then, I would tell the interviewer that normally I would write test cases first to test each of these bullets, and ask them if they want me to do that here. Assuming they say no, as I write the code, I would keep each of these bullets in mind, and check them off as I am fairly certain they work.

Doing this planning step is something you could and should definitely practice yourself with some of the easier problems on Project Euler or from the Elements of Programming Interviews book.

I noticed that even on a whiteboard, I always end up writing bugged code or code that doesn’t compile.

I’ve seen this happen in interviews and it often is followed by a statement of denial. The candidate will struggle to write effective code, and then make statements like “I write better code than this”. The problem here is that the candidate just demonstrated that he/she does not.

While you can counter argue that the problem is context. That solving problems in an interview is not the same as in the quiet private space of your own desk. It is the interview context that matters to successfully get the job for that quiet desk.

I realize that perhaps interviewers might want to look at how I write code and/or how I solve problems rather than proof-compiling my whiteboard code

There is no solution to a problem if it does not compile, and interviewers can see how you write code once you’ve put it on the whiteboard.

Your argument is this: My problem solving abilities with this programming language are not relative to my understanding of the languages syntax and compiling rules.

If you want to demonstrate only your problem solving abilities, then ask to solve the problem in a different programming language. One that you will not make mistakes in.

how should I approach the above problem in mental terms, i.e. what mental steps should I follow when writing code for an interview with the two bullet points above

Practice:

Google popular programming challenges for interviews, and then practice solving them. If the whiteboard presents a challenge then buy a whiteboard and practice on one.

Practice writing source code on paper with a pen. Review your work for compile accuracy and then work on improving it.

Study the rules for the compiler you are using.

There is no easy answer other than to work on improving oneself in the areas they are weakest.

Good luck on your interviews.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật