{"id":26754951,"url":"https://github.com/pcisha/find-words-in-a-dictionary","last_synced_at":"2025-11-05T09:02:51.877Z","repository":{"id":264577912,"uuid":"867543680","full_name":"pcisha/Find-Words-in-a-Dictionary","owner":"pcisha","description":"Find Words in a Dictionary","archived":false,"fork":false,"pushed_at":"2024-11-25T05:52:32.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-11T14:39:41.918Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pcisha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-04T09:08:54.000Z","updated_at":"2024-11-25T05:52:35.000Z","dependencies_parsed_at":"2024-11-25T06:37:16.003Z","dependency_job_id":null,"html_url":"https://github.com/pcisha/Find-Words-in-a-Dictionary","commit_stats":null,"previous_names":["pcisha/find-words-in-a-dictionary"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pcisha/Find-Words-in-a-Dictionary","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcisha%2FFind-Words-in-a-Dictionary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcisha%2FFind-Words-in-a-Dictionary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcisha%2FFind-Words-in-a-Dictionary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcisha%2FFind-Words-in-a-Dictionary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pcisha","download_url":"https://codeload.github.com/pcisha/Find-Words-in-a-Dictionary/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcisha%2FFind-Words-in-a-Dictionary/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":282791624,"owners_count":26727829,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-05T02:00:05.946Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-28T14:17:24.054Z","updated_at":"2025-11-05T09:02:51.841Z","avatar_url":"https://github.com/pcisha.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Find Words in a Dictionary\n\n***Objective:***\n\nImplement a function named `findWords` that accepts two arguments: 1) an input string and 2) a dictionary. This\nfunction should return an array of words from the dictionary that can be formed by rearranging some or all of the\nletters in the input string. Each letter in the input string may be used up to once per word.\n\n**Function signature:**\n\n```tsx\nfunction findWords(inputString: string, dictionary:string[]): string[]\n```\n\n**Input:**\n\n- **`inputString`**(type:**`string`**): A string consisting of lowercase English letters. The string may contain\n  repeated letters.\n- **`dictionary`**(type:**`string[]`**): An array that specifies the universe of valid output words. You can assume all\n  words will consist of lowercase English letters.\n\n**Test Cases:**\n\n```jsx\nconsole.log(findWords(\"ate\", [\"ate\", \"eat\", \"tea\", \"dog\", \"do\", \"god\", \"goo\", \"go\", \"good\"]));\n// Expected output: [\"ate\", \"eat\", \"tea\"]\n\nconsole.log(findWords(\"oogd\", [\"ate\", \"eat\", \"tea\", \"dog\", \"do\", \"god\", \"goo\", \"go\", \"good\"]));\n// Expected output: [\"dog\", \"do\", \"god\", \"goo\", \"go\", \"good\"]\n```\n\n## Solution\n\n### Approach\n\nThe solution involves the following key steps:\n\n1. **Character Count Comparison**:\n\n- For each word in the dictionary, check if it can be formed using the characters from the input string by comparing\n  character counts.\n\n2. **Helper Functions**:\n\n- `countChars`: Counts the occurrences of each character in a string.\n- `canFormWord`: Checks if a word can be formed from the character counts of the input string.\n\n3. **Main Function**:\n\n- `findWords`: Iterates through the dictionary and uses `canFormWord` to determine if each word can be formed from\n  the input string's characters.\n\n### Execution\n\nCompile and run the TypeScript file:\n\n`npx tsc findWords.ts`\n\n`node findWords.js`\n\n### Tech Stack\n\nTypeScript, Node.js, npm, Git, IntelliJ IDEA.\n\n### Time and Space Complexity\n\n`countChars` Function:\n\nTime Complexity: O(n), where n is the length of the string.\nSpace Complexity: O(1), since the maximum number of unique characters (lowercase English letters) is constant (26).\n\n`canFormWord` Function:\n\nTime Complexity: O(m), where m is the length of the word.\nSpace Complexity: O(1), for the same reason as above.\n\n`findWords` Function:\n\nTime Complexity: O(d * k), where d is the number of words in the dictionary and k is the average length of the words.\nSpace Complexity: O(d), for the result array.\n\n## Summary\n\nThis `README.md` file includes a clear description of the problem and the approach taken to solve,\ntime and space complexity analysis, and instructions on how to run the code.\nThis should provide a comprehensive overview for anyone reviewing the repository.\n\nDate: August 7, 2024.\n\nAuthor: Prachi Shah @ https://pcisha.my.canva.site/\n\nP.S. The default copyright laws apply.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpcisha%2Ffind-words-in-a-dictionary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpcisha%2Ffind-words-in-a-dictionary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpcisha%2Ffind-words-in-a-dictionary/lists"}