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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:50:06+00:00 2026-06-15T07:50:06+00:00

Hello guys I have the following problem: INPUT : 2 ababaa aa OUTPUT :

  • 0

Hello guys I have the following problem:

INPUT:
2
ababaa
aa

OUTPUT:
11
3

Explanation:
For the first case, the suffixes of the string are “ababaa”, “babaa”, “abaa”, “baa”, “aa” and “a”. The similarities of each of these strings with the string “ababaa” are 6,0,3,0,1,1 respectively. Thus the answer is 6 + 0 + 3 + 0 + 1 + 1 = 11.

For the second case, the answer is 2 + 1 = 3.

This part works , but some of the test that my code should pass don’t.

Here is my code

def input_data
#STDIN.flush
tries = gets.chomp
end

strings=[];
tries = input_data until (tries =~ /^[1-9]$/)
tries = tries.to_i
strings << input_data until (strings.count == tries)

strings.map do |x|
values = 0
current = x.chars.to_a
(0..x.length-1).map do |possition| 
    current_suffix = x[possition..-1].chars.to_a
    (0..current_suffix.length-1).map do |number|
        if (current_suffix[0] != current[0])
            break
        end

        if ( current_suffix[number] == current[number] )
            values = values+1
        end
    end 
  end

  if (values != 0)
    puts values
  end
end

Any suggestions how to fix it ??

  • 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-06-15T07:50:07+00:00Added an answer on June 15, 2026 at 7:50 am

    gets returns nil, which cannot be chomped. Therefore, you need to make sure, that you work on an actual string before calling chomp. A common idiom in ruby is to use the ||= operator to set a variable only if it is nil. So you would write:

    tries = gets        # get input
    tries ||= ''        # set to empty string if nil
    tries.chomp!        # remove trailing newline  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello guys I have a problem with my application involving Lucene java library and
Hello guys i have set background image on my input text and text area
Hello guys i have a problem streaming PDF files with php, i'm using this
Hello guys, I have a general design problem with iPhone application. I want to
Hello guys i have a little problem i get an error: File C:\Users\kokki\Desktop\gb1\main.py, line
Hello guys I have the following method: var usuario; usuario = UniapontaService.GetUsuarioUniapontaPlanejamentoEstrategico(x => x.IdUsuario
Hello guys i have a small problem at my console application i have a
Hello Guys I have encountered a weirld problem I am not able to debug
hello guys i have a simple problem the has me stumped. i really dont
Hello guys i have dataform in silverlight 4 project item source is: ItemsSource={Binding Data,

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.