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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:49:09+00:00 2026-06-13T08:49:09+00:00

If I have an array of numbers like [5, 2, 3, 2, 0, 2]

  • 0

If I have an array of numbers like [5, 2, 3, 2, 0, 2]

I want to count the number of times I can continuously index the array until we come to an index we already visited, like this:

A[0] = 5 
A[5] = 2
A[2] = 3
A[3] = 2 stop here because we already indexed 2.

So my problem is: without using additional data structure to store the previously visited indices, is there a way I can tell my program when to stop indexing?

  • 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-13T08:49:10+00:00Added an answer on June 13, 2026 at 8:49 am

    It appears that you are treating this array as a directed graph. If that is so, then what you’re really asking for is how to detect cycles in a directed graph.

    See:

    • Best algorithm for detecting cycles in a directed graph
    • Find all paths with cycles in directed graph, given the source vertex
    • How to detect if a directed graph is cyclic?

    To answer your question specifically though: If you were wandering around in a labyrinth, how do you tell if you’ve been to a particular junction before? You might consider dropping breadcrumbs or unspooling a thread to remind you where you have been. It’s the same thing here. You’ll need to either annotate your original array with a “visited” flag, or keep a copy of the indexes you’ve visited in your own array.

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

Sidebar

Related Questions

I'd like to have a MATLAB array fill a column with numbers in increments
I have a number array and I'd like to calculate the median. When the
I have an array of numbers: @numbers = 1,2,3,6,8,9,11,12,13,14,15,20 and I want to print
I have an array in ASP that looks like this: 3,5,7,7,3,2,3 What I want
I have an array with a few values and want to do something like
i want to output an array containing numbers. I'm creating the array like this
I have 3 arrays like this: 1st Array ( [0695] => Array ( [loan_number]
Lets say I have an array numbers that contains the following values: int numbers
Consider the following scenario . I have an array of numbers: [ 1,2,3,4 ]
I have an array of phone numbers, and I need a fast way 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.