Hello,
I think you can use a hash table to speed up the query.
1) Create a hash table of words, with key values as characters, and values as positions of characters。
Word: Hello
User Input: eao
2)Find the character entered by the user: ‘e’,
Find by hash table, find the index greater than 0 (you can use binary search)。
The word index is at position 1.
3) Find the character entered by the user: ‘a’,
Find by hash table, find index greater than 1 (you can use binary search)
'A' not found, index does not move
4)Find the character entered by the user: ‘o’,
Find by hash table, find the index greater than 0 (you can use binary search)。
The word index is at position 4.
I'm not familiar with js, I can't implement it with code, I'm really sorry.
Hello, I think you can use a hash table to speed up the query. 1) Create a hash table of words, with key values as characters, and values as positions of characters。 Word: Hello User Input: eao
2)Find the character entered by the user: ‘e’, Find by hash table, find the index greater than 0 (you can use binary search)。 The word index is at position 1.
3) Find the character entered by the user: ‘a’, Find by hash table, find index greater than 1 (you can use binary search) 'A' not found, index does not move
4)Find the character entered by the user: ‘o’, Find by hash table, find the index greater than 0 (you can use binary search)。 The word index is at position 4.
I'm not familiar with js, I can't implement it with code, I'm really sorry.