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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:11:11+00:00 2026-06-19T01:11:11+00:00

Assume you have a function matchWithMagic that returns a Boolean value for a given

  • 0

Assume you have a function matchWithMagic that returns a Boolean value for a given string. You don’t know any detail how it do it but you know the result of true means “Match”. Assuming the complexity of this function is linear in time and space to the size of input string.

Now the question is to implement a function that for a given string, that will return an pair of integers, namely pos and len such that matchWithMagic(substring(inputstring,pos,len)) matches and pos is the least number that this can be true (earliest match). When pos is known, len is the least number for a match (shortest match, with a lower priority). There are no requirement on efficiency but the answer should includes performance analyse.

For example, suppose the magic function return true for input strings contains “Good Guy!” or “Bad Guy!” your function should return pos=5,len=8 for “Good Bad Guy!”.

Preferred languages is C/C++/Java/JavaScript/C#/Basic, but other languages are OK.

UPDATE

A trivial answer has now been posted. I hope a more efficient solution could appear.

  • 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-19T01:11:12+00:00Added an answer on June 19, 2026 at 1:11 am

    Given that the function is black-box, I’m not sure you can do better than this:

    for (int pos = 0:n)
    for (int len = 0:(n-pos))
      if (matchWithMagic(substring(inputstring,pos,len)))
        return {pos, len};
    return null;
    

    Which I believe is O(n^3) (assuming matchWithMagic is O(n)).

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

Sidebar

Related Questions

Lets assume i have a function that takes 32bit integer in, and returns random
lets assume that i have function named printuser() now if i have string like
Assume i have the following function: def select_queryset(value_to_decide_upon): this function returns either any of
Assume I have a function: void isUniqueSymbols(string stream) How to understand that I should
Let's assume I have a main function that performs a boolean logical test to
In ERLANG: Assume we have a function f() that takes F1 as inputs where
I have a question regarding static function in php. let's assume that I have
I'm having a trouble with my math: Assume that we have a function: F(x,y)
Assume that I have a class value object defined in php, where each variable
Assume that I have a boost::function of with an arbitrary signature called type CallbackType

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.