Closed pallasivasai closed 1 month ago
Hi @pallasivasai! Thanks for opening this issue. We appreciate your contribution to this open-source project. Your input is valuable and we aim to respond or assign your issue as soon as possible. Thanks again!
@pallasivasai, please follow our DSA structure.
---
id: enter-id-for-routes
title: Title of Problem
sidebar_label: Number of Problem
tags: [tag1, tag2, ...., tagn]
description: Write description for SEO in few words and in only string and can't use any HTML tags in this line
sidebar_position: enter position number
---
## Problem Statement
### Problem Description
<!-- Content here -->
### Examples
<!-- Problem Examples here -->
### Constraints
<!-- Problem Constraints here -->
## Solution of Given Problem
### Intuition and Approach
<!-- Content here -->
### Approaches
<!-- Content here -->
#### Codes in Different Languages
<Tabs>
<TabItem value="JavaScript" label="JavaScript" default>
<SolutionAuthor name="@username"/>
```javascript
// code here
<div style={{display: 'flex', flexWrap: 'wrap', justifyContent: 'space-between', gap: '10px'}}> {['github_username'].map(username => (
))}
### Detailed Guidelines
- id: Unique identifier for the route.
- title: Title of the problem.
- sidebar_label: Problem number or label for the sidebar.
- tags: Relevant tags for the problem.
- description: A short SEO-friendly description. No HTML tags.
Hello @pallasivasai! Your issue #3530 has been closed. Thank you for your contribution!
Is there an existing issue for this?
Feature Description
0244- Shortest Word Distance II
The problem provides us with the task of designing a data structure that must be able to compute the shortest distance between any two distinct strings within an array of strings. This implies that we first need to initialize the data structure with an array of strings, which we'll refer to as wordsDict. Once initialized, we should be able to query this data structure with two different strings, and it should return the smallest possible index difference between these two strings within the wordsDict array.
This could be visualized as an array where we want to find the minimum distance between two elements, where the elements are the positions of the words we're interested in. For example, if wordsDict is ["practice", "makes", "perfect", "coding", "makes"], and we query for the distance between "coding" and "practice", the returned value should be 3, as the closest "practice" to "coding" is three indices away.
Use Case
Let's demonstrate how the WordDistance class and its methods work using a simple example.
Suppose our wordsDict is ["the", "quick", "brown", "fox", "quick"]. We initialize the WordDistance class with this list of strings. During the initialization process, the class builds the hash map self.d which will contain:
"the" -> [0] "quick" -> [1, 4] "brown" -> [2] "fox" -> [3] Now, let's say we want to find the shortest distance between the words "brown" and "quick". We call the shortest method with these two words. Here's what happens inside this method:
Benefits
No response
Add ScreenShots
No response
Priority
High
Record