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

  • Home
  • SEARCH
  • 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 4609116
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:56:28+00:00 2026-05-22T00:56:28+00:00

There is a homework I should do and I need help. I should write

  • 0

There is a homework I should do and I need help. I should write a program to find the first substring of length k that is repeated in the string at least twice.

For example in the string “banana” there are two repeated substrings of length 2: “an” , “na”. In this case, the answer is “an” because it appeared sooner than “na”

Note that the simple O(n^2) algorithm is not useful since there is time limit on execution time of program so I guess it should be in linear time.

There is a hint too: Use Hash table.

I don’t want the code. I just want you to give me a clue because I have no idea how to do this using a hash table. Should I use a specific data structure too?

  • 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-22T00:56:29+00:00Added an answer on May 22, 2026 at 12:56 am

    Iterate over the character indexes of the string (0, 1, 2, …) up to and including the index of the second-from-last character (i.e. up to strlen(str) – 2). For each iteration, do the following…

    Extract the 2-char substring starting at the character index.

    Check whether your hashtable contains the 2-char substring. If it does, you’ve got your answer.

    Insert each 2-char substring into the hashtable.

    This is easily modifiable to cope with substrings of length k.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As the title says, I need to write a small program to read data
As a homework i need to make a webapp that will play an mp3
I'm a student and I got a homework i need some minor help with
Okay, for a homework assignment my professor wants us to write a program in
There is a conversion process that is needed when migrating Visual Studio 2005 web
There are two popular closure styles in javascript. The first I call anonymous constructor
There is a field in my company's Contacts table. In that table, there is
I am trying to write a small PHP function that would go through a
hi i need to write sucj kind of sorting maybe it is similary to
For homework, I need to build a small java application.The main goal is to

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.