对象已移动

可在此处找到该文档 Generate all possible strings formed by replacing letters with given respective symbols – New Self New Life
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

NFT Aggregator Marketplace Development: Complete Overview
Softwares

NFT Aggregator Marketplace Development: Complete Overview

by admin
August 15, 2025
How agile is your crypto? Interview study explores opportunities and challenges of cryptographic update processes
Softwares

How agile is your crypto? Interview study explores opportunities and challenges of cryptographic update processes

by admin
August 12, 2025
20+ Best Free Futuristic Fonts in 2025 — Speckyboy
Softwares

20+ Best Free Futuristic Fonts in 2025 — Speckyboy

by admin
August 13, 2025
This week in AI dev tools: GPT-5, Claude Opus 4.1, and more (August 8, 2025)
Softwares

This week in AI dev tools: GPT-5, Claude Opus 4.1, and more (August 8, 2025)

by admin
August 9, 2025
How Agentic AI Powers Webkul eCommerce Marketplaces
Softwares

How Agentic AI Powers Webkul eCommerce Marketplaces

by admin
August 11, 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
More than 400 Canadian artists sign letter denouncing ‘anti-trans’ policies

More than 400 Canadian artists sign letter denouncing ‘anti-trans’ policies

April 1, 2024
Taylor Swift’s ‘Eras Tour’ movie: How and when you can stream in Canada – National

Taylor Swift’s ‘Eras Tour’ movie: How and when you can stream in Canada – National

November 27, 2023
Jacklyn Zeman, longtime ‘General Hospital’ actor, dies at 70 – National

Jacklyn Zeman, longtime ‘General Hospital’ actor, dies at 70 – National

May 11, 2023
Greyson Chance says Ellen DeGeneres ‘abandoned’ him, calls her ‘manipulative’ and ‘opportunistic’ – National

Greyson Chance says Ellen DeGeneres ‘abandoned’ him, calls her ‘manipulative’ and ‘opportunistic’ – National

September 26, 2022
Robert De Niro shows up to troll Donald Trump outside hush-money trial – National

Robert De Niro shows up to troll Donald Trump outside hush-money trial – National

May 29, 2024
Anne Heche to be taken off life support after compatible organ recipient found – National

Anne Heche to be taken off life support after compatible organ recipient found – National

August 15, 2022
Mike ‘The Situation’ Sorrentino saves 2-year-old son from choking in home video – National

Mike ‘The Situation’ Sorrentino saves 2-year-old son from choking in home video – National

February 5, 2024
‘Nope’ movie review: Jordan Peele does it again in masterful spectacle – National

‘Nope’ movie review: Jordan Peele does it again in masterful spectacle – National

July 22, 2022
Hip-Hop’s Biggest First-Week Sales for Projects in 2025

Hip-Hop’s Biggest First-Week Sales for Projects in 2025

August 15, 2025
HyperX’s claims its latest headset lasts 250 hours on a single charge

HyperX’s claims its latest headset lasts 250 hours on a single charge

August 15, 2025
Kate Middleton, Prince William Rare Message Amid Summer Break

Kate Middleton, Prince William Rare Message Amid Summer Break

August 15, 2025
As the Mule Strikes Again, Gaal and Demerzel’s Confrontation Takes an Unexpected Turn

As the Mule Strikes Again, Gaal and Demerzel’s Confrontation Takes an Unexpected Turn

August 15, 2025
YouTube Adds Custom App Promotions for Shorts

YouTube Adds Custom App Promotions for Shorts

August 15, 2025
Tragic Death at 2025 Elements Festival Under Investigation

Tragic Death at 2025 Elements Festival Under Investigation

August 14, 2025
J’Adore! Rebecca Adlington is c’est chic on This Morning wearing a ‘Postcard from Paris’ Boden dress

J’Adore! Rebecca Adlington is c’est chic on This Morning wearing a ‘Postcard from Paris’ Boden dress

August 14, 2025
John Slattery on if He’ll Ever Do a Mad Men Reboot

John Slattery on if He’ll Ever Do a Mad Men Reboot

August 14, 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

  • Hip-Hop’s Biggest First-Week Sales for Projects in 2025
  • HyperX’s claims its latest headset lasts 250 hours on a single charge
  • Kate Middleton, Prince William Rare Message Amid Summer Break
  • 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.

New Self New Life