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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:42:57+00:00 2026-06-04T21:42:57+00:00

I mean in reverse sorry, essentially, find the first true element, then circularly move

  • 0

I mean in reverse sorry, essentially, find the first true element, then circularly move backwards until you find the last valid element, once the last element that is true is found by circularly reverse traversing the array, circularly go forward and push until a false is found.

I am given an array of pair of bool,int.

The array always has 4 elements. Elements that are true are circularly linked together ex:

TFFT
TTFT
FFTT
FTTT
TFFF
FTTF

These are all valid arrays that I could have.
The number they contain is not important for this (the pair second value).

What I need to do is:
only keep the true ones. But I need them to stay in the correct circular order such that the last valid true element will come first.

So for example:
If my array was:

T 1
F 2
F 3
T 4

The new array needs to be:

T 4
T 1

Another example:
If my array was:

F 1
T 2
T 3
F 4

The new array needs to be:

T 2
T 3

This is just an abstract example of the problem. The actual code is complex and hard to read. But if I know how to do this I’ll be alright.

Essentially I need to walk clockwise from the first discontinuous element to the last contiguous element.

Thanks

Edit:
By circularly linked together I mean that if the 4th and first element are true, they are not disconnected meaning they are not discontiguous, 3,4,1 is considered contiguous.

Thus if you had TFTT then I need them to be in the order of 3,4,1.

  • 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-04T21:42:59+00:00Added an answer on June 4, 2026 at 9:42 pm

    You can think of your array as containing three segments:

    1. 0 or more T elements at the beginning
    2. 1 or more F elements in the middle
    3. 0 or more T elements at the end

    (If your array might not have any F elements at all, then you can handle that as a special case.)

    What you want is a new array containing segment 3 followed by segment 1, with segment 2 erased.

    Here’s an outline of an algorithm to do that:

    • Find the index of the first F in the array. Call it first_F.
    • Find the index of the last F in the array. Call it last_F.
    • Now you know your segments occupy the indices [0, first_F), [first_F, last_F], and [last_F + 1, size_of_array), respectively.
    • Iterate over the segment [last_F + 1, size_of_array) and add the elements to your result array.
    • Iterate over the segment [0, first_F) and add those elements to your result array.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First I want to clearify that I mean by reverse engineering something like decompiling
i was trying to reverse engineer a website ( www.asklaila.com ) to find out
I mean the reverse of this function: styleObj = window.getComputedStyle(node); So something like this:
I mean the small exit/cancel button marked with an X in the top right
I mean things like: FK1 -> 1FK2 -> 2PK Please, note that 1FK2 is
I mean something like this: http://www.globalscaletechnologies.com/p-25-sheevaplug-dev-kit-uk.aspx My minimal hardware requirement is: Ethernet card UPDATE:
I mean, if I have an object and I apply 3 transforms to it,
I mean when the user starts my application(exe). I want it to start directly
I mean library and syntax of C#.
I mean, I want the logger name to reflect the source.jsp file, no matter

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.