My solution to a “Coding Problem” focused on algorithmic problem solving, that I came across.

You are given two strings, a ‘parent’ string and a ‘query’ string respectively. Your task is
to determine how many times the query string – or an anagram of the query string –
appears in the parent string.

Here’s my solution in Typescript,

anagramDetect(problem: string, query: string): number {
    if(problem == null || query  == null) {
        return 0;
    }
    if(query.length > problem.length) {
        return 0;
    }
    let n = 0
    let sortJoin = (a:string) => a.split('').sort().join('');
    let sortedQ = sortJoin(query);
    problem.split('').map((_, i) => {
        if (sortJoin(problem.substr(i, query.length)) == sortedQ) {
            n += 1;
        }
    });
    return n; 
}

Get updates?

As usual, if you find any of my posts useful support me by  buying or even trying one of my apps on the App Store. 

https://mydaytodo.com/apps/

Also, if you can leave a review on the App Store or Google Play Store, that would help too.

Categories: Algorithms

2 Comments

ufabet · September 25, 2020 at 10:31 pm

With havin so much written content do you ever run into any problems of plagorism
or copyright infringement? My website has a lot of completely unique content I’ve either created myself
or outsourced but it seems a lot of it is popping it up all over the
internet without my permission. Do you know any methods to help protect against content from being ripped off?

I’d certainly appreciate it.

Solitaire · February 26, 2021 at 1:56 pm

Hi there, I enjoy reading through your article post.
I wanted to write a little comment to support you.

Leave a Reply

Verified by MonsterInsights