Menu
Coddy logo textTech

Practice #3

Lesson 12 of 14 in Coddy's Hash Tables - Data Structures Series #4 course.

challenge icon

Challenge

Easy

Write a function isAnagram that gets two strings s1 and s2 and returns whether they are anagrams: the same multiset of characters in any order.

The comparison is case-sensitive. Strings of different lengths are never anagrams.

You must use the HashMap class provided in hashmap.<ext> — do not use language built-ins like sets, dicts, or maps.

Try it yourself

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "solution.h"

int main() {
    char s1[8192];
    char s2[8192];
    if (!fgets(s1, sizeof(s1), stdin)) s1[0] = '\0';
    if (!fgets(s2, sizeof(s2), stdin)) s2[0] = '\0';
    s1[strcspn(s1, "\r\n")] = '\0';
    s2[strcspn(s2, "\r\n")] = '\0';
    bool r = isAnagram(s1, s2);
    printf("%s\n", r ? "true" : "false");
    return 0;
}

All lessons in Hash Tables - Data Structures Series #4