{}
CODE VISUALIZER
Master DSA, Python and C with step-by-step code visualization.
See it in action
CODE VISUALIZER
Master DSA, Python and C with step-by-step code visualization.
See it in action
run-icon
Main.cs
using System; using System.Collections.Generic; using System.Linq; class Program { static Dictionary<char, int> ListToCountDict(List<char> l) { Dictionary<char, int> counts = new Dictionary<char, int>(); foreach (char item in l) { if (counts.ContainsKey(item)) { counts[item]++; } else { counts[item] = 1; } } return counts; } static void Main() { string str = "aqaswasldkaslfaslyetdop"; var duplLetters = new HashSet<char>(ListToCountDict(str.ToList()).Where(kvp => kvp.Value > 1).Select(kvp => kvp.Key)); string resS = new string(str.Where(s => !duplLetters.Contains(s)).ToArray()); List<int> binaryDup = str.Select(s => duplLetters.Contains(s) ? 1 : 0).ToList(); int max = 0; int cur = 0; foreach (int b in binaryDup) { if (b == 0) { cur = 0; } else { cur += b; } if (cur > max) { max = cur; } } Console.WriteLine($"Result String: {resS}, Max: {max}"); } }
Output