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

  • Home
  • SEARCH
  • 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 39515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:52:37+00:00 2026-05-10T14:52:37+00:00

This question is about removing sequences from an array, not duplicates in the strict

  • 0

This question is about removing sequences from an array, not duplicates in the strict sense.

Consider this sequence of elements in an array;

[0] a [1] a [2] b [3] c [4] c [5] a [6] c [7] d [8] c [9] d 

In this example I want to obtain the following…

[0] a [1] b [2] c [3] a [4] c [5] d 

Notice that duplicate elements are retained but that sequences of the same element have been reduced to a single instance of that element.

Further, notice that when two lines repeat they should be reduced to one set (of two lines).

[0] c [1] d [2] c [3] d 

…reduces to…

[0] c [1] d 

I’m coding in C# but algorithms in any language appreciated.

  • 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. 2026-05-10T14:52:38+00:00Added an answer on May 10, 2026 at 2:52 pm

    Here’s C# app i wrote that solves this problem.

    takes
    aabccacdcd

    outputs
    abcacd

    Probably looks pretty messy, took me a bit to get my head around the dynamic pattern length bit.

    class Program {     private static List<string> values;     private const int MAX_PATTERN_LENGTH = 4;      static void Main(string[] args)     {         values = new List<string>();         values.AddRange(new string[] { 'a', 'b', 'c', 'c', 'a', 'c', 'd', 'c', 'd' });           for (int i = MAX_PATTERN_LENGTH; i > 0; i--)         {             RemoveDuplicatesOfLength(i);         }          foreach (string s in values)         {             Console.WriteLine(s);         }     }      private static void RemoveDuplicatesOfLength(int dupeLength)     {         for (int i = 0; i < values.Count; i++)         {             if (i + dupeLength > values.Count)                 break;              if (i + dupeLength + dupeLength > values.Count)                 break;              var patternA = values.GetRange(i, dupeLength);             var patternB = values.GetRange(i + dupeLength, dupeLength);              bool isPattern = ComparePatterns(patternA, patternB);              if (isPattern)             {                 values.RemoveRange(i, dupeLength);             }         }     }      private static bool ComparePatterns(List<string> pattern, List<string> candidate)     {         for (int i = 0; i < pattern.Count; i++)         {             if (pattern[i] != candidate[i])                 return false;         }          return true;     } } 

    fixed the initial values to match the questions values

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

Sidebar

Ask A Question

Stats

  • Questions 110k
  • Answers 110k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Without knowing what the UI is like there is the… May 11, 2026 at 9:32 pm
  • Editorial Team
    Editorial Team added an answer Use System.Decimal: The Decimal value type represents decimal numbers ranging… May 11, 2026 at 9:32 pm
  • Editorial Team
    Editorial Team added an answer Before we write any code, let's discuss the difference between… May 11, 2026 at 9:32 pm

Related Questions

When I am writing code in Python, I often need to remove items from
I'm a Lisp beginner. I'm trying to memoize a recursive function for calculating the
I have a HashMap (although I guess this question applies to other collections) of
I was confused when I first started to see anti-singleton commentary. I have used

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.