0% found this document useful (0 votes)
1 views2 pages

JS - Coding Problems and Solutions

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views2 pages

JS - Coding Problems and Solutions

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

Anagrams

const str1 = "aaz";

const str2 = "zza";

const anagrams = (str1,str2)=>{

if([Link]!==[Link]){

return false;

let freq = {};

for(let val of str1){

freq[val] = (freq[val] || 0)+1;

for(let val of str2){

if(!freq[val]){

return false;

else{

freq[val]-=1;

return true;

[Link](anagrams(str1,str2)); //false

Time complexity -O(n)

2. find longest word in string

let str1 = “I am sreevani malipeddi, I am UI developer”;

[Link](str1);

let str2 = [Link](/[^\w\s]/g,''); // here we replacing special characters other than words and
spaces with ‘’

[Link](str2);

let words = [Link](" ");


let longword="";

for(let word of words){

if([Link]>[Link]){

longword = word;

[Link](longword); // malipeddi

You might also like