Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6762183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:17:12+00:00 2026-05-26T14:17:12+00:00

I got this question in an interview the other day and would like to

  • 0

I got this question in an interview the other day and would like to know some best possible answers(I did not answer very well haha):

Scenario: There is a webpage that is monitoring the bytes sent over a some network. Every time a byte is sent the recordByte() function is called passing that byte, this could happen hundred of thousands of times per day. There is a button on this page that when pressed displays the last 100 bytes passed to recordByte() on screen (it does this by calling the print method below).

The following code is what I was given and asked to fill out:

public class networkTraffic {
    public void recordByte(Byte b){
    }
    public String print() {
    }
}

What is the best way to store the 100 bytes? A list? Curious how best to do this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:17:13+00:00Added an answer on May 26, 2026 at 2:17 pm

    Something like this (circular buffer) :

    byte[] buffer = new byte[100];
    int index = 0;
    
    public void recordByte(Byte b) {
       index = (index + 1) % 100;
       buffer[index] = b; 
    }
    
    public void print() {
       for(int i = index; i < index + 100; i++) {
           System.out.print(buffer[i % 100]);
       }
    }
    

    The benefits of using a circular buffer:

    1. You can reserve the space statically. In a real-time network application (VoIP, streaming,..)this is often done because you don’t need to store all data of a transmission, but only a window containing the new bytes to be processed.
    2. It’s fast: can be implemented with an array with read and write cost of O(1).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got this question in an interview and I was not able to solve
I got asked this question in a interview. I clearly know what a decorator
I just got this question on a SE position interview, and I'm not quite
I just got this question on an interview and had no idea how to
I got this in an interview question -- the question was more about what
I got this question from my cousin: What will be the best way to
I got this question in an interview with amazon. I was asked to perform
My girlfriend got this question in an interview, and I liked it so much
I got this question in a previous interview and couldnt do it , any
I got this question in Interview for post of SSE in ASP.NET. the interview

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.