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

AI updates from the past week: IBM watsonx Orchestrate updates, web search in Anthropic API, and more — May 9, 2025
Softwares

AI updates from the past week: IBM watsonx Orchestrate updates, web search in Anthropic API, and more — May 9, 2025

by admin
May 11, 2025
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
A faster, sleeker JavaScript experience
Softwares

A faster, sleeker JavaScript experience

by admin
May 10, 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
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
Anant Ambani wedding: Celebs, wealthy elite attend lavish billionaire festivities – National

Anant Ambani wedding: Celebs, wealthy elite attend lavish billionaire festivities – National

March 1, 2024
Phantom Parade Gets Opening Movie, Cast Announced

Phantom Parade Gets Opening Movie, Cast Announced

March 8, 2022
Guide for Odoo Website Razorpay Checkout Payment Acquirer

Guide for Odoo Website Razorpay Checkout Payment Acquirer

January 6, 2023
I Tried Calocurb For 90 Days. Here’s My Review.

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

January 8, 2025
Best Cryptocurrency Wallets Comparison | SCAND Blog

Best Cryptocurrency Wallets Comparison | SCAND Blog

July 30, 2022
The Best Crime Shows on Netflix

The Best Crime Shows on Netflix

May 27, 2023
Eric Clapton’s ‘Unplugged’ and the Peak Dad Rock Moment

Eric Clapton’s ‘Unplugged’ and the Peak Dad Rock Moment

May 12, 2025
Niall Horan Returning to The Voice as Coach

Niall Horan Returning to The Voice as Coach

May 12, 2025
Kate Middleton makes huge announcement with the help of Prince William in new teaser video

Kate Middleton makes huge announcement with the help of Prince William in new teaser video

May 12, 2025
Apple reportedly plans to hike prices of upcoming iPhones

Apple reportedly plans to hike prices of upcoming iPhones

May 12, 2025
Who Is Shane Lowry’s Wife? Wendy’s Job & Kids

Who Is Shane Lowry’s Wife? Wendy’s Job & Kids

May 12, 2025
The Best Luxury Sportswear Brands for Men in 2025

The Best Luxury Sportswear Brands for Men in 2025

May 12, 2025
The Most Visited Websites in the World [Infographic]

The Most Visited Websites in the World [Infographic]

May 12, 2025
I’m Frustrated With How Many New Characters Played A Critical Role At The End Of This Episode

I’m Frustrated With How Many New Characters Played A Critical Role At The End Of This Episode

May 11, 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

  • Eric Clapton’s ‘Unplugged’ and the Peak Dad Rock Moment
  • Niall Horan Returning to The Voice as Coach
  • Kate Middleton makes huge announcement with the help of Prince William in new teaser video
  • 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.

slot machine casino online