Settings Results in 4 milliseconds

Kint Debugging not Showing (Drupal 8 Web Developme ...
Category: Technology

Tips and Tricks ...


Views: 263 Likes: 87
[SEO] Why Using Links Instead of Click Functions f ...
Category: Network

[SEO ] Why Using Links Instead of Click Functions is very important ...


Views: 337 Likes: 82
Why you should choose HomeAssistant as your Home A ...
Category: Research

Home automation is becoming increasingly popular as people look for ways to make their homes mor ...


Views: 0 Likes: 37
ASP.NET 8 Best Practices: Coding, Performance Tips ...
Category: .Net 7

In this chapter, we will explore various best practices and performance tips to enhance your ASP. ...


Views: 368 Likes: 98
Tips Tricks When Drawing Realistic Photo
Category: Art

One of the important mistakes to avoid when drawing a detailed picture is to damage th ...


Views: 0 Likes: 29
ASP.NET Core 3.1 Get the Path to the Images Folder ...
Category: .Net 7

Problem How do you get the path to the wwwroot folder to show an image without ...


Views: 775 Likes: 112
What is the best practices for creating a robots.t ...
Category: Research

Creating a robots.txt file is an important step in protecting your website from malicious bots a ...


Views: 0 Likes: 24
Linked Server and SSIS
Category: Servers

<a href="https//docs.microsoft.com/en-us/sql/relational-databases/linked-servers/create-linked-serv ...


Views: 347 Likes: 111
How to Find Good Drawing Paper
Category: Art

Advanced Section <p clas ...


Views: 0 Likes: 26
How to optimize sql query in Microsoft SQL Server
Category: SQL

1. Keep in mind that when you write a Store Procedure SQL Server generates an SQL plan. If you ha ...


Views: 463 Likes: 102
Entity Framework Core 6 and 7 Tips and Tricks
Category: Entity Framework

Interceptors in EF Core 7- Use the TPC (Table per Concrete) Mapping strategy (prefer ...


Views: 0 Likes: 29
SQL Server Import and Export Wizard Error: Data co ...
Category: SQL

Problem Error 0xc02020a1 Data Flow Task 1 Data conversion failed. The data co ...


Views: 4100 Likes: 153
.NET Developer Needed in OH
Category: Jobs

Role You Wi ...


Views: 213 Likes: 85
How to increase Speed of Social Media application
Category: Computer Programming

Speed of the Web Application is really ...


Views: 0 Likes: 40
[Git] Your local changes to the following files wo ...
Category: Git

[Git Error] You ...


Views: 451 Likes: 84
How to find out the Highest Number in an Array in ...
Category: .Net 7

Question How do you find out the highe ...


Views: 125 Likes: 69
Full time Javascript Developer wanted!
Category: Jobs

An award winning account firm local to Cleveland/Akron, OH is looking for a mid level (3-6 years ...


Views: 38 Likes: 89
[JSON Data and Percent Sign] Passing big data with ...
Category: Databases

<span style="font-weight bold; font-size large; text-decoration-l ...


Views: 306 Likes: 74
SQL Server Tips and Tricks
Category: SQL

Error Debugging Did you know you could double click on the SQL Error and ...


Views: 0 Likes: 44
Solved!! Ruby on Rails Server Wont Start Error
Category: Technology

When you run "rails s -b 0.0.0.0" into a bash command console and the Rails Server does not start, l ...


Views: 365 Likes: 92
Front-End Development Tips and Tricks
Category: Front-End

1. Did you know you could make a form (Html Tag) a parent of different other <st ...


Views: 45 Likes: 61
How to Scale SQL Server Google Bard vs ChatGPT Res ...
Category: Servers

Google Bard There are two ways to scale SQL Server scaling up and scaling ...


Views: 0 Likes: 28
Clean JSON Data in Excel
Category: Databases

When working with data, it is important to know tips and tricks that will save you a lot of time. As ...


Views: 320 Likes: 105
SQL table Design Best Practices
Category: SQL

When working with SQL tables, sometimes it is frustrating to find no columns with "Date" the data wa ...


Views: 280 Likes: 101
What is Computer Programming
Category: Computer Programming

<div class="group w-full text-gray-800 darktext-gray-100 border-b border-black/10 darkborder-gray- ...


Views: 0 Likes: 17
SQL 0x80004005  Description: "Cannot continue the ...
Category: SQL

Question How do you solve for t ...


Views: 0 Likes: 42
Solved!! Visual Studio 2019 Shows a big Cursor and ...
Category: Technology

Problem When coding in Visual Studio, all of the sudden you see a big cursor and when you start ...


Views: 800 Likes: 98
Be Aware of Memory Leak in Software Application
Category: Technology

Memory Leak in Software Application<div style="text-align ce ...


Views: 333 Likes: 98
Determine if two strings are anagrams with C# .NET
Determine if two strings are anagrams with C# .NET

Two strings are anagrams if they are made up of the same set of characters. Examples “hello” and “loleh”“123123” and “312312”“qwerty” and “wretqy” The degree of “anagram-ness” can vary ignore case?ignore non-numeric characters?ignore whitespace? In this post we’ll only consider word-characters only and the comparison will be case-insensitive to make the problem more interesting. We’ll write a function that accepts two integers and returns a boolean true if the strings are anagrams, otherwise false. We’ll look at two solutions out of many that exist out there using a character mapusing string sort What is a character map? It is a map where the key is of type char and the value if of type integer. We collect the unique characters of a string and count how many times each character occurs in the string. E.g. CharCount‘f’2‘g’1‘i’2‘d’1‘o’1 We do that for both strings and compare the counts of each unique character. Let’s start with a skeleton using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace Algorithms { public class Anagram { public bool AreAnagrams(string first, string second) { if (first == null || second == null) return false; return AreAnagramsWithCharMap(first, second); //return AreAnagramsWithSortedStrings(first, second); } private bool AreAnagramsWithCharMap(string first, string second) { return false; } private bool AreAnagramsWithSortedStrings(string first, string second) { return false; } private Dictionary<char, int> MakeCharacterMap(string input) { string cleaned = CleanInput(input); return cleaned.Distinct().ToDictionary(c => c, c => cleaned.Count(s => s == c)); } private string CleanInput(string input) { return Regex.Replace(input, @"[_]+|[^\w]+|[\d-]+", "").ToLower(); } } } We start by some null-checking and return false if either of the two inputs is null. The AreAnagramsWithCharMap function has been wired up but it’s not yet implemented. The function for the second solution AreAnagramsWithSortedStrings has also been prepared. We have two private functions as well CleanInputthis one takes a string and strips all underscores, white space and non-word characters from it and returns the lower-case version of itMakeCharacterMapfirst we clean the incoming input stringsecond we use a couple of LINQ operators to build the character mapDistinct() to gather the unique characters from the stringToDictionary() to build the map itself, the key will be the character itself and for the value we count the number of occurrences of that character in the string Let’s look at the implementation of AreAnagramsWithCharMap private bool AreAnagramsWithCharMap(string first, string second) { var charMapFirst = MakeCharacterMap(first); var charMapSecond = MakeCharacterMap(second); if (charMapFirst.Count != charMapSecond.Count) { return false; } return charMapFirst.All(kvp => charMapSecond.ContainsKey(kvp.Key) ? kvp.Value == charMapSecond[kvp.Key] false); } We first create the two character maps. If they differ in size then we can immediately return false. It means that one of the strings has at least one more character than the other so it’s pointless to continue. Otherwise we make use of the All LINQ operator which return true of all the elements of a collection fulfil a certain condition. The condition is based on two parameters whether the character map contains the character as the key in the first placewhether that character occurs with the same frequency as in the source map If both conditions are fulfilled for all characters in the character maps then we return true. Here’s a set of unit tests using System; using System.Collections.Generic; using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Algorithms.Tests { [TestClass] public class AnagramTests { [TestMethod] public void AreAnagramsTests() { Anagram a = new Anagram(); Assert.IsTrue(a.AreAnagrams("hello", "___ hllOe!! 456 ???")); Assert.IsFalse(a.AreAnagrams("sdfs", null)); Assert.IsFalse(a.AreAnagrams(null, "sdfs")); Assert.IsFalse(a.AreAnagrams(null, null)); Assert.IsFalse(a.AreAnagrams("qwerty", "yewr")); Assert.IsFalse(a.AreAnagrams("qwerty", "qwertyuiop")); Assert.IsTrue(a.AreAnagrams("? par**lIame%%nt !", "partIAL men")); Assert.IsTrue(a.AreAnagrams("a gentleman", "elegant man")); } } } The will all pass. The second solution takes the two cleaned strings, puts them in order and compares them. This solution is slightly less performant than the first one due to the string ordering though. The map comparison doesn’t involve any ordering so it’s somewhat quicker. Here’s the implemented function private bool AreAnagramsWithSortedStrings(string first, string second) { string sortedOne = string.Concat(CleanInput(first).OrderBy(c => c)); string sortedTwo = string.Concat(CleanInput(second).OrderBy(c => c)); return sortedOne == sortedTwo; } We again clean the input string and then call the OrderBy LINQ operator. It returns an ordered collection of characters from the string, i.e. not an ordered string. Hence we need to embed this bit of code in string.Concat so that we build the string again from the characters. Finally we simply compare the two strings. Wire up this function from the main one and rerun the unit tests. They will still pass. public bool AreAnagrams(string first, string second) { if (first == null || second == null) return false; //return AreAnagramsWithCharMap(first, second); return AreAnagramsWithSortedStrings(first, second); }


How to draw an eye in eight steps
Category: Art

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;In this blog post, I will ex ...


Views: 447 Likes: 104
How to Prompt ChatGPT and Google Bard for Best Res ...
Category: Machine Learning

Here are some tips for prompting Google Bard Be specific. The more specific you a ...


Views: 0 Likes: 34
Here is what is going on this week at ErnesTech.co ...
Category: General

Hello readers,Inside this article, you will read about "Why ErnesTech is Developing o ...


Views: 0 Likes: 48
How to Optimize SQL Query in SQL Server
Category: Other

There are several ways to tune the performance of an SQL query. Here are a few tips < ...


Views: 0 Likes: 9
How to Use a well Known Drawing Method to Achieve ...
Category: Art

The Grid Method is a method of drawing an outline from a reference photo onto paper. T ...


Views: 0 Likes: 35
WLED and BTF-Light Strip and ESP 32 Configuration
Category: Home

1. Make sure that you have flashed wled software on ESP 32 using install.wled.me&nbsp; &nbs ...


Views: 0 Likes: 30
Front-End Bootstrap Development Notes Tips and Tri ...
Category: .Net 7

How to remove borders from a Boostrap 5 Table Do you find yourself adding "border-0" to e ...


Views: 0 Likes: 27
Coding Bootcamp Graduate Searching for Job
Category: Jobs

Hello! I am a recent graduate from the coding Bootcamp Tech Elevator and am actively searching fo ...


Views: 214 Likes: 114
PERMANENT ROLE | WEB APPLICATION DEVELOPER | MOREL ...
Category: Jobs

<span style="font-weight bold; tex ...


Views: 300 Likes: 94
Nginx: Kill all Nginx process on Linux and Run a c ...
Category: Linux

Nginx Tips and Tricks Tip 1. Kill all process for nginx [If there are pr ...


Views: 893 Likes: 110
How to Optimize Web Server for Faster Response Tim ...
Category: Technology

How to Optimize ...


Views: 338 Likes: 75
How to optimize Search Engines to Rank Dynamic Dat ...
Category: Computer Programming

Dynamic data is kind of hard to inde ...


Views: 0 Likes: 30
C-Sharp 11 Tips and Tricks
Category: Research

Linq- Did you know you could compair two sequences by using sequence operations li ...


Views: 90 Likes: 58
What You Need to Know about Candles
Category: Candles

There are a few important things to know about candles, especially if you are using them for the ...


Views: 0 Likes: 26
Linked Server and SSIS
Category: Servers

<a href="https//docs.microsoft.com/en-us/sql/relational-databases/linked-servers/create-linked-serv ...


Views: 357 Likes: 117
Design Parterns in C-Sharp
Category: C-Sharp

Design Patterns (C#)< ...


Views: 366 Likes: 105
How to Use Spans in C-Sharp ( Stackalloc, Heap and ...
Category: .Net 7

Read about Spans ...


Views: 145 Likes: 67
Google like a pro
Category: Technology

As a Software Developer, it is important to know how to find good information in the fastest manner. ...


Views: 311 Likes: 101
What is the best way to learn AI in 2024?
Category: Research

IntroductionArtificial Intelligence (AI) has been around for decades, but it's only in r ...


Views: 0 Likes: 26
Everything Access Tutorials
Category: Technology

<span style="font-size medium; font-weight bold; textline under ...


Views: 327 Likes: 82
Visual Studio 2019 Development
Category: Tools

Visual Studio Development Tips ...


Views: 373 Likes: 129
Tips and Trick Developing in C# and Dotnet 8
Category: Other

<div class="group w-full text-gray-800 darktext-gray-100 border-b border-black/10 darkborder-gray- ...


Views: 0 Likes: 8

Login to Continue, We will bring you back to this content 0



For peering opportunity Autonomouse System Number: AS401345 Custom Software Development at ErnesTech Email Address[email protected]