Facebook Interview Question for Software Engineers

Country: United States
Interview Type: In-Person

Comment hidden because of low score. Click to expand.
of 1 vote

Looking for interview experience sharing and coaching?
Visit A++ Coding Bootcamp at aonecode.com.

Given by experienced engineers/interviewers from FB, Google and Uber,
our ONE TO ONE courses cover everything in an interview including
latest interview questions sorted by companies,
SYSTEM DESIGN Courses (highly recommended for people interviewing with FLAG)
ALGORITHMS (conquer DP, Graph, Greedy and other advanced algo problems),
and mock interviews.

Our students got offers from G, U, FB, Amz, Yahoo and other top companies after a few weeks of training.

Feel free to email us aonecoding@gmail.com with any questions. Thanks!

public class CircularBuffer<T> {

        private T[] buffer;

        private int tail;

        private int head;

        public CircularBuffer(int n) {
            buffer = (T[]) new Object[n];
            tail = 0;
            head = 0;

        public void add(T toAdd) {
            if (head != (tail - 1)) {
                buffer[head++] = toAdd;
            } else {
                //throw new BufferOverflowException();
            head = head % buffer.length;

        public T get() {
            T t = null;
            int adjTail = tail > head ? tail - buffer.length : tail;
            if (adjTail < head) {
                t = (T) buffer[tail++];
                tail = tail % buffer.length;
            } else {
                //throw new BufferUnderflowException();
            return t;

        public String toString() {
            return "CircularBuffer(size=" + buffer.length + ", head=" + head + ", tail=" + tail + ")";


- aonecoding June 06, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

class my_exception: public exception {
    std::string reason;
    my_exception(string s) : reason(s) {}

    virtual const char* what() const throw()  {
        return reason.c_str();

class cb {
  int sz;
  int *buffer;
  int count;
  int rindex, windex;
  cb(int mz) : sz(mz+1), count(0), rindex(0), windex(0) {
      buffer = new int[sz];
      bzero(buffer, sizeof(int)*(sz));
  bool full() {
      return ((windex + 1)%sz == rindex)? true: false;
  bool empty() {
      return rindex == windex? true: false;
  bool add(int v) {
      if (rindex == windex) {
          return false;
          // assert on count == sz;
      buffer[windex] = v;
      windex = (windex+1)%(sz);
      if (full()) {
          cout << " the CR is full \n";
      return true;
  int get() {
      if (empty()) {
          throw my_exception("Empty");
      int v = buffer[rindex];
      rindex = (rindex+1)%sz;
      if (empty()) {
          cout << " the buffer is empty\n";
      return v;

int main() {
	// your code goes here
	cb cr(3);
	try {
	if(!cr.add(4)) {
	    cout << "4 cant be added\n";
	cout << cr.get() <<"\t" << cr.get() << "\t" << cr.get() <<"\n";
	cout <<"Getting the 4th element \n";
	} catch(const exception &e) {
	    cout << "Exception caught at addng " << e.what() <<"\n";

- ali.kheam June 07, 2017 | Flag Reply

Add a Comment

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.


is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More


CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More