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 3699544
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:06:56+00:00 2026-05-19T05:06:56+00:00

A common interview question asks to write an algorithm that detects duplicates in a

  • 0

A common interview question asks to write an algorithm that detects duplicates in a string.
Using a character array of length 128 to keep track of the characters already seen is a good way to solve this problem in linear time.

In C we would type something like

char seen_chars[128];
unsigned char c;

/* set seen_chars to all zeros, assign c */

seen_chars[ c ] = 1;

To mark character c as seen. Of course this relies on

(int) c 

returning a value between 0 and 127.

I’m wondering when would this fail? What are the assumptions that make this code work correctly?

  • 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-19T05:06:57+00:00Added an answer on May 19, 2026 at 5:06 am

    The code will fail (and cause undefined behavior) every time when the integer value of the given char c is not between 0 and 127 (inclusive).

    C does in no way limit the maximum range of char – you are only guaranteed that it can hold at least 256 distinct values – so in any given C implementation a valid char value can be out of that boundary. On most desktop systems a char can hold values from -128 to 127, or from 0 to 255. However, as an example:

    char aFunction(void);
    char c = aFunction();
    if ((int)c > 1000000000)
        printf("This could be true on some systems\n").
    

    The following would be valid (although it may exhaust your stack on systems with large chars):

    #include <limits.h>
    _Bool seen[1<<CHAR_BIT] = {0};
    seen[(unsigned char)c] = 1;
    /* etc. */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the most common question in interview that what is asp.net life cycle?
A common argument against using .NET for high volume, transactional enterprise systems is that
This is a common interview question (according to some interview sites) but I can
In an interview question, Interviewer asked me What is the common and difference between
This was the question asked in an interview. NullPointerException is very common; why is
So, this is a common interview question. There's already a topic up, which I
Common question but I could use an english explanation. Is it like Java where
A common pattern in C++ is to create a class that wraps a lock
A common scenario when using source control is to have a development branch along
The common sense tells that the Doxygen comment blocks have to be put in

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.