All Questions
23 questions
2
votes
3
answers
1k
views
Find the 'n' most frequent words in a text, aka word frequency
I'm doing freeCodeCamp's Coding Interview Prep to improve my JavaScript skills. This challenge is called "Word Frequency", and is based on the Rosetta Code's entry of the same name.
The ...
2
votes
2
answers
441
views
Numeronym generation
Problem statement
I need to generate numeronyms from a string, let's say qwerty as follows:
qwerty
q1erty
q2rty
q3ty
q4y
Code
...
1
vote
1
answer
367
views
Capitalize the First Letter of Words in a String (JavaScript, Python)
Problem
Write a function that accepts a string, capitalizes the first letter of each word in the string, and returns the capitalized string.
Examples
...
1
vote
1
answer
162
views
Anagram (Python, JavaScript)
Problem
Write a function to check whether two given strings are anagram of each other or not. An anagram of a string is a string that contains same characters ([A-Za-z0-9]) and the order of ...
3
votes
2
answers
1k
views
Palindrome and Reverse a String Problems (JavaScript, Python)
Problem 1
Given a string, the task is to reverse the string and return a reversed string.
Problem 2
Given a string, return true if the string is a palindrome or false if it is not.
Code
Just for ...
5
votes
4
answers
1k
views
Confirm the ending of a string
Challenge:
Check if a string (first argument, str) ends with the given target
string (second argument, target).
This ...
3
votes
1
answer
1k
views
Shortest way to form a string out of a subsequence of a string
The task is taken from LeetCode (subscription required) -
From any string, we can form a subsequence of that string by deleting
some number of characters (possibly no deletions).
Given two strings ...
3
votes
4
answers
301
views
Finding the Longest Word in a String
Challenge:
Return the length of the longest word in the provided sentence.
I've made a solution that works but it is kinda bad since the time complexity is \$O(n \log n)\$ and it involves mutation.
...
1
vote
1
answer
531
views
Find all starting indices in a string which are anagrams of a word
The task:
Given a word W and a string S, find all starting indices in S which
are anagrams of W.
For example, given that W is "ab", and S is "abxaba", return 0, 3, and
4.
My solution:
<...
1
vote
1
answer
645
views
Find out whether string A can be shifted to get string B
The task:
Given two strings A and B, return whether or not A can be shifted some
number of times to get B.
For example, if A is abcde and B is cdeab, return true. If A is abc
and B is acb, ...
5
votes
1
answer
4k
views
Find longest common string subsequence
The task (also found at https://www.youtube.com/watch?v=10WnvBk9sZc):
Write a function that takes two strings, s1 and s2, and returns the longest common subsequence of s1 and s2.
"ABAZDC", "...
0
votes
3
answers
197
views
Form a string consisting of the common letters that appear in two input strings
The idea is to write a function that takes two strings and returns a new string that repeats in the previous two: examples:
...
5
votes
2
answers
5k
views
Longest common prefix
I have made a function for finding the longest common prefix for the challenge on the leetcode site. This is the code:
...
8
votes
5
answers
12k
views
Find palindromic substrings as efficiently as possible
I've written a function to calculate all the distinct substrings of a given string, that are palindromes. The string is passed as the argument to the function. For example, the string abba is a ...
3
votes
2
answers
3k
views
Find all occurrences of all permutations of a shorter string within a longer string
Input is two strings, the first string being the long string and the second smaller string being the permuted string.
The output should return the starting indices of all occurrences as well as the ...