Giter VIP home page Giter VIP logo

weekend-health-take-home's Introduction

weekend-health-take-home

Weekend Health Take-home Challenge

findWords.ts is a typescript program, it first needs to be complied into JS file to get the output. If tsc complier is already installed then use following command to compile, else install tsc compiler first

tsc --target es6 findWords.ts

Above command will generate js file which can be executed using node

node findWords.js

Approach

  1. Create a frequency map of each letter in inputString with key as a letter and value as frequency count.
  2. Iterate over each word in dictonary, and check if this word can be formed[Step 3 to determine how word can be formed] using inputString frequncy map, if yes, then push in result array.
  3. How to know word can be formed:- Iterate over each letter of word from dictionary, and look up into inputString frquency map(from step 1), if frequency is zero or letter is not present, then word can not be formed, else update map with frequncy count minus 1 for the letter and continue checking all the other letters in the word until all match.
  4. Finally result array will have all the words from dictionary that can be formed.

Complexity Analysis

Time Complexity

if input string has length n and dictionary has total words m

Creating inputString frequncy map:- O(n)

Iterating over m words, and check each n letters in frequncy map:- O(m*n)

Final time complexity will be O(n + m*n).

Space Complexity

inputString frequncy map :- O(n)

Copy inputString frequncy map for each word in dictionary:- O(m)

Final space complexity will be O(m*n + n).

weekend-health-take-home's People

Contributors

pgodha avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.