> ## Content Index
> Fetch the complete content index at: https://developerinsider.co/llms.txt
> Use this file to discover other available public pages before exploring further.

# Find Anagram String - Programming Puzzles
- URL: https://developerinsider.co/find-anagram-string-programming-puzzles/
- Published: 2016-10-16T11:40:31.000Z
- Updated: 2026-09-09T11:28:23.000Z
- Author: Vineet Choudhary
- Tags: Programming Puzzles, Puzzles

Given two strings, work out if they both have exactly the same characters in them.

#### Example

**Input**

```
word, wrdo

```

This returns `true` because they are the same but just scrambled.

**Input**

word, wwro  
This returns `false`.

#### Rules

Here are the rules!

- Assume input will be at least 1 char long, and no longer than 8 chars.
- No special characters, only a–z
- All inputs can be assumed to be lowercase

#### Test Cases

```
boat, boat = true
toab, boat = true
oabt, toab = true
a, aa = false
zzz, zzzzzzzz = false
zyyyzzzz, yyzzzzzy = true
sleepy, pyels = false
p,p = true

```

## Solutions

**Jump to [C](#c), [JavaScript](#javascript), [PHP](#php), [C#](#csharp) Solution.**  
You can submit your own solution in [comment section](#comments) in same/different programming language. If your solution is better or in different language we'll add here.

## C

```c
#include <stdio.h>

t[256],i;
int main(c)
{
    for(;c+3;)
        (i=getchar())>10?t[i]+=c:(c-=2);
    for(i=257;--i&&!t[i-1];);
    puts(i?"false":"true");
    return 0;
}

```

## JavaScript

```js
<html>
<body>
    <script>
        function a(b){
            return b.split('').sort().join()
        }
        alert(a('abc')==a('bca'));
     </script>
</body>
</html>

```

## PHP

```php
function d($s){
    return array_count_values(str_split($s));
}

echo d($argv[1]) == d($argv[2]);

```

## CSharp

```c#
using System;
using System.Linq;

namespace testcs
{
    class Program
    {
        static void Main(string[] args)
        {
            string a="asd", b="sda";
            Console.Write(a.OrderBy(_ => _).SequenceEqual(b.OrderBy(_ => _)));
        }
    }
}

```