New Self New Life
No Result
View All Result
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices
New Self New Life
No Result
View All Result
Home Softwares

Generate all possible strings formed by replacing letters with given respective symbols

by admin
4 years ago
in Softwares
Best Coding Practices For Rest API Design
Share on FacebookShare on Twitter


Given a string S consisting of N characters and an array M[] of pairs of characters such that any character M[i][0] may be changed with the character M[i][1] within the string S, the duty is to generate all of the doable strings shaped by changing some characters of the string with their respective symbols within the array M[].

Examples:

Enter: S = “aBc”, M = {‘a’ : ‘$’, ‘B’ : ‘#’, ‘c’ : ‘^’}
Output:
aBc
aB^
a#c
a#^
$Bc
$B^
$#c
$#^ 

Enter: S = “a”, M={‘a’ : ‘$’}
Output:
a
$

Strategy: The given downside may be solved by utilizing Backtracking to generate all doable strings by changing every character with the mapped character within the array M[]. Comply with the steps beneath to resolve the issue:

  • Retailer all of the pairs of the mapped characters within the array M[] in a map, say Map.
  • Outline a recursive perform say generateLetters(S, P), the place S is the modified string and P is the index of the present character:
    • Test for the bottom case i.e., if index P equals to the N then print the string S and return.
    • Don’t change the present character and recursively name for the perform, generateLetters(S, P + 1).
    • Now, change the character, S[P] with the respective image within the map M and name for the perform, generateLetters(S, P+1).
  • After finishing the above steps, name for the perform generateLetters(S, 0) to print all doable strings.

Under is the implementation of the above method:

C++

  

#embrace <bits/stdc++.h>

utilizing namespace std;

  

void generateLetters(string S, int P,

                     unordered_map<char, char> M)

{

    

    if (P == S.measurement()) {

        cout << S << "n";

        return;

    }

  

    

    

    generateLetters(S, P + 1, M);

  

    

    S[P] = M[S[P]];

  

    

    

    generateLetters(S, P + 1, M);

  

    return;

}

  

int foremost()

{

    string S = "aBc";

    unordered_map<char, char> M;

    M['a'] = '$';

    M['B'] = '#';

    M['c'] = '^';

    M['d'] = '&';

    M['1'] = '*';

    M['2'] = '!';

    M['E'] = '@';

  

    

    generateLetters(S, 0, M);

  

    return 0;

}

Output:


aBc
aB^
a#c
a#^
$Bc
$B^
$#c
$#^

Time Complexity: O(N*2N)
Auxiliary House: O(1)

Consideration reader! Don’t cease studying now. Pay money for all of the vital DSA ideas with the DSA Self Paced Course at a student-friendly value and change into business prepared.  To finish your preparation from studying a language to DS Algo and plenty of extra,  please refer Full Interview Preparation Course.

In case you want to attend dwell courses with specialists, please refer DSA Stay Lessons for Working Professionals and Aggressive Programming Stay for College students.



Source link

Tags: formedGeneratelettersreplacingrespectivestringssymbols
Previous Post

Space Jam 2 Tops Weekend Box Office With Surprise $32 Million

Next Post

DARKSIDE ‘Spiral’ album | Nicolás Jaar and Dave Harrington

Related Posts

Unlocking the Future of Finance
Softwares

Unlocking the Future of Finance

by admin
May 8, 2025
Address bar tweaks – Vivaldi Browser snapshot 3683.4
Softwares

Address bar tweaks – Vivaldi Browser snapshot 3683.4

by admin
May 7, 2025
How WordPress Agencies Can Improve Site Building Efficiency — Speckyboy
Softwares

How WordPress Agencies Can Improve Site Building Efficiency — Speckyboy

by admin
May 6, 2025
Grand Theft Auto VI delayed again, this time until May 2026
Softwares

Grand Theft Auto VI delayed again, this time until May 2026

by admin
May 5, 2025
User Guide for Odoo Advance Website Blog Search
Softwares

User Guide for Odoo Advance Website Blog Search

by admin
May 4, 2025
Next Post
DARKSIDE ‘Spiral’ album | Nicolás Jaar and Dave Harrington

DARKSIDE 'Spiral' album | Nicolás Jaar and Dave Harrington

Object.entries

Dark Mode in One Line of Code!

  • Trending
  • Comments
  • Latest
Cameron Monaghan Discusses Erotic Thriller

Cameron Monaghan Discusses Erotic Thriller

January 13, 2022
Doctor Strange: 12 Best Comic Issues Of The 1990s

Doctor Strange: 12 Best Comic Issues Of The 1990s

December 11, 2021
I Tried Calocurb For 90 Days. Here’s My Review.

I Tried Calocurb For 90 Days. Here’s My Review.

January 8, 2025
Phantom Parade Gets Opening Movie, Cast Announced

Phantom Parade Gets Opening Movie, Cast Announced

March 8, 2022
Justin Bieber postpones remaining shows of Justice World Tour due to health concerns – National

Justin Bieber postpones remaining shows of Justice World Tour due to health concerns – National

October 8, 2022
10 Underrated 2022 TV Shows You Might Have Missed

10 Underrated 2022 TV Shows You Might Have Missed

January 4, 2023
New Python and Data Analysis Workshops [Article]

New Python and Data Analysis Workshops [Article]

August 27, 2021
The Definitive 30-Step Basic SEO Checklist for 2022

The Definitive 30-Step Basic SEO Checklist for 2022

January 3, 2022
Sabrina Carpenter Responds To Met Gala Outfit Backlash

Sabrina Carpenter Responds To Met Gala Outfit Backlash

May 8, 2025
9 Pure Money Saving Hacks Every South African Should Know

9 Pure Money Saving Hacks Every South African Should Know

May 8, 2025
Snapchat Announces AI-Powered Ad Updates, and Expanded Sponsored Snaps

Snapchat Announces AI-Powered Ad Updates, and Expanded Sponsored Snaps

May 8, 2025
Who Are the Stars? – Hollywood Life

Who Are the Stars? – Hollywood Life

May 8, 2025
What Metalcore Songs Made You Cry? Reddit Users Discuss

What Metalcore Songs Made You Cry? Reddit Users Discuss

May 7, 2025
Unlocking the Future of Finance

Unlocking the Future of Finance

May 8, 2025
ROKR Dream Gift Factory Wooden Music Box kit review

ROKR Dream Gift Factory Wooden Music Box kit review

May 7, 2025
Kelly Clarkson Details Dating Life After Divorce

Kelly Clarkson Details Dating Life After Divorce

May 7, 2025
New Self New Life

Your source for entertainment news, celebrities, celebrity news, and Music, Cinema, Digital Lifestyle and Social Media and More !

Categories

  • Celebrity
  • Cinema
  • Devices
  • Digital Lifestyle
  • Entertainment
  • Music
  • Social Media
  • Softwares
  • Uncategorized

Recent Posts

  • Sabrina Carpenter Responds To Met Gala Outfit Backlash
  • 9 Pure Money Saving Hacks Every South African Should Know
  • Snapchat Announces AI-Powered Ad Updates, and Expanded Sponsored Snaps
  • Home
  • Disclaimer
  • DMCA
  • Privacy Policy
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2021 New Self New Life.
New Self New Life is not responsible for the content of external sites. slotsfree  creator solana token

No Result
View All Result
  • Home
  • Entertainment
  • Celebrity
  • Cinema
  • Music
  • Digital Lifestyle
  • Social Media
  • Softwares
  • Devices

Copyright © 2021 New Self New Life.
New Self New Life is not responsible for the content of external sites.

best gambling sites