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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:03:52+00:00 2026-06-10T05:03:52+00:00

Given a sequence like: 1,2,1,2,1,1,1,2,1,2,1,3,1,2,1,2,1,3 What is an efficient way to obtain the minimum

  • 0

Given a sequence like:

1,2,1,2,1,1,1,2,1,2,1,3,1,2,1,2,1,3

What is an efficient way to obtain the minimum ordering:

1,1,1,2,1,2,1,3,1,2,1,2,1,3,1,2,1,2

The brute force approach is obvious so please don’t recommend it — unless to provide a convincing proof that the brute force approach is the only way to do it!

More detail

I have an algorithm that generates a list of numbers. The output of the algorithm is a list / array, but logically the numbers represent a loop, where only the relative order of the elements matters. In order to store these loops for later comparison I want to put store them in such a way that the one-dimensional list of numbers stored represents the minimum ordering of the elements in the loop. A picture would be most helpful:

Loop

This loop describes the path around the T tetromino, where 1 is move forward, 2 is turn right, and 3 is turn left. It doesn’t matter where you start or even which direction you go, following this sequence of 18 moves will get you a T tetromino. The output of the algorithm which produces this loop will return the elements with an arbitrary starting point and direction. So the returned array could be:

Arbitrary initial ordering:

1,2,1,2,1,1,1,2,1,2,1,3,1,2,1,2,1,3

Arbitrary order

There is one minimum ordering, though. It can be obtained from two different circuits, reflecting the fact that the T tetromino is symmetrical:

Minimum ordering:

1,1,1,2,1,2,1,3,1,2,1,2,1,3,1,2,1,2

Minimum order

Brute force

The obvious brute force method is to construct all possible orderings and take the minimum. My question is whether there is a more clever and efficient way of doing this.

  • 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-10T05:03:53+00:00Added an answer on June 10, 2026 at 5:03 am

    This is a well-studied problem called the lexicographically minimal string rotation.

    The better algorithms all run in O(n) time as opposed to O(n*n) for the naive algorithm.

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

Sidebar

Related Questions

I would like to know if anyone sees a pattern in the sequence given
Given an input sequence, what is the best way to find the longest (not
Given a table like below, is there a single-query way to update the table
Using Groovy, I'd like to generate a random sequence of characters from a given
I would like to be able to visualize the call sequence for a given
When given an d you could be dealing with a fixed sequence like a
given is any sequence of integers like 23 7 13 4 8 6 .
Quite simply, given a sequence in F#, how does one obtain elements from index
Given sequence : [1,A,B,C,2,F,K,L,5,6,P,I,E] The numbers represent items that I identify as headers, whereas
Given a sequence of data (it may have duplicates), a fixed-sized moving window, move

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.