Giter Site home page Giter Site logo

poojasahu10 / minimum-distance-between-words-of-a-string Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 2 KB

Given a big chunk of string data or a book stored in s , the task is to count the the minimum count of words between two given words(w1 and w2).

C++ 100.00%

minimum-distance-between-words-of-a-string's Introduction

Given a big chunk of string data or a book stored in s , the task is to count the the minimum count of words between two given words(w1 and w2). Chunk of data : Paragraphs are the building blocks of papers

Input : s = “Paragraphs are the building blocks of papers” w1 = “are”, w2 = “the” Output : 0 There is no word between “are” and “the”. They both occur together.

Input s = “Paragraphs are the building blocks of papers” w1 = “Paragraphs”, w2 = “the” Output : 1 There is a word “are” in between “Paragraphs” and “the”

An approach to the above problem statement when count search is to be done recursively on the same chunk of string instead of going through the entire string every time is to organise the strings into data structure. Create a map of words in the string as key and store the indices of the words into the list in sorted way.

Explanation : s = “Paragraphs are building blocks of papers. Paragraphs are formed of multiple sentences” The above string shall be arranged in a map with words as key and list of indices of the word. { Paragraphs : [0,6] are : [1,7] building : [2] blocks : [3] of : [4,9] papers : [5] formed : [8] multiple : [10] sentences : [11] }

We will use the above map to find the count of minimum number of words : For example : w1=”Paragraphs”, w2=”of”, minimum count is 2. We will get the list of indices for “Paragraphs” and “of” and get the minimum difference of the indices.

The below example gets minimum count without going through the whole string in each iteration.

Example :

Enter the words terms length Word count : 1 Continue for next set of words? Press Y or y for yes Y Enter the words geeks practice Either of words not in the list Continue for next set of words? Press Y or y for yes Y Enter the words least sentences Word count : 1 Continue for next set of words? Press Y or y for yes n or N for no

minimum-distance-between-words-of-a-string's People

Watchers

James Cloos avatar Pooja Sahu 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.