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

Applications of Artificial Intelligence in Business
Softwares

Applications of Artificial Intelligence in Business

by admin
June 4, 2025
How to Add Custom Style Variations to WordPress Blocks — Speckyboy
Softwares

How to Add Custom Style Variations to WordPress Blocks — Speckyboy

by admin
June 2, 2025
Smart software replaces expensive sensors for glass wall detection with 96% accuracy
Softwares

Smart software replaces expensive sensors for glass wall detection with 96% accuracy

by admin
June 1, 2025
User Guide For UnoPim PDF Generator
Softwares

User Guide For UnoPim PDF Generator

by admin
May 31, 2025
Infragistics Ultimate 25.1 includes updates across several of its UI toolkit components
Softwares

Infragistics Ultimate 25.1 includes updates across several of its UI toolkit components

by admin
May 29, 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
How to Build a JavaScript Search [Article]

How to Build a JavaScript Search [Article]

August 30, 2022
Advancement in predicting software vulnerabilities

Advancement in predicting software vulnerabilities

May 21, 2022
Product Information Management Trends (PIM)

Product Information Management Trends (PIM)

February 4, 2022
15 Best Movies Like Parasite

15 Best Movies Like Parasite

February 20, 2022
I Tried Calocurb For 90 Days. Here’s My Review.

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

January 8, 2025
Credit Scoring Software Development Guide

Credit Scoring Software Development Guide

May 13, 2022
What Are the Best User Provisioning Practices for SaaS Apps

What Are the Best User Provisioning Practices for SaaS Apps

September 9, 2022
Neal Schon Teases Potential Return of Co-Founding Journey Member

Neal Schon Teases Potential Return of Co-Founding Journey Member

November 28, 2022
With Their New Single, 2ŁØT and Aloe Blacc Inspire Us to Become ‘Immortal’

With Their New Single, 2ŁØT and Aloe Blacc Inspire Us to Become ‘Immortal’

June 5, 2025
Has The Survivors Season 2 Been Canceled or Renewed?

Has The Survivors Season 2 Been Canceled or Renewed?

June 5, 2025
Turning Disaster Into Relief: The Purpose-Driven Growth of Insurance Claim HQ

Turning Disaster Into Relief: The Purpose-Driven Growth of Insurance Claim HQ

June 5, 2025
Rogue Traders singer Natalie Bassingthwaighte celebrates second anniversary with partner Pip Loth

Rogue Traders singer Natalie Bassingthwaighte celebrates second anniversary with partner Pip Loth

June 5, 2025
X Adds Verification Explainers To Avoid EU Fines

X Adds Verification Explainers To Avoid EU Fines

June 5, 2025
Leah Remini Addresses Rumors of a Rift with Jennifer Lopez

Leah Remini Addresses Rumors of a Rift with Jennifer Lopez

June 5, 2025
Eminem’s Publishing Company Battles Meta in $109 Million Lawsuit

Eminem’s Publishing Company Battles Meta in $109 Million Lawsuit

June 4, 2025
TESmart thunderbolt KVM switch review – great as long as you’re fine with 4k60FPS or 2K screens

TESmart thunderbolt KVM switch review – great as long as you’re fine with 4k60FPS or 2K screens

June 4, 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

  • With Their New Single, 2ŁØT and Aloe Blacc Inspire Us to Become ‘Immortal’
  • Has The Survivors Season 2 Been Canceled or Renewed?
  • Turning Disaster Into Relief: The Purpose-Driven Growth of Insurance Claim HQ
  • 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