TCS Digital Coding Questions:
Question 1:
Write a program to find the count of numbers that consists of unique digits.
Input:
Input consists of two Integer lower and upper value of a range
Output:
The output consists of a single line, print the count of unique digits in a given range. Else Print”No Unique Number“.
Solution:
//codewindow.in #include<bits/stdc++.h> using namespace std; void printUnique(int l, int r) { int count=0; for (int i=l ; i<=r ; i++) { int num = i; bool visited[10] = {false}; while (num) { if (visited[num % 10]) break; visited[num%10] = true; num = num/10; } if (num == 0) count++; } if(count>0) cout<<count; else cout<<"No Unique Number"; } int main() { int l,r; cin>>l>>r; printUnique(l, r); return 0; } //end
Question 2:
There is a range given n and m in which we have to find the count all the prime pairs whose difference is 6. We have to find how many sets are there within a given range.
Output:
The output consists of a single line, print the count prime pairs in a given range. Else print”No Prime Pairs”.
Constraints:
2 ≤ n ≤ 1000
n ≤ m ≤ 2000
Sample Input:
4
30
Sample Output:
6
Explanation:
(5, 11) (7, 13) (11, 17) (13, 19) (17, 23) (23, 29) . we have 6 prime pairs.
Solution:
//codewindow.in #include <bits/stdc++.h> using namespace std; void count_prime(int l, int r) { int count=0; bool prime[r + 1]; memset(prime, true, sizeof(prime)); for (int p = 2; p * p <= r; p++) { if (prime[p] == true) { for (int i = p * 2; i <= r; i += p) prime[i] = false; } } for (int i = l; i <= r - 6; i++) if (prime[i] && prime[i + 6]) count++; if(count>0) cout<<count; else cout<<"No Prime Pairs"; } int main() { int n,m; cin>>n>>m; count_prime(n, m); return 0; } //end
Question 3:
Write a program to print all the combinations of the given word with or without meaning (when unique characters are given).
Sample Input:
abc
Sample Output:
abc
acb
bac
bca
cba
cab
Solution:
//codewindow.in #include<bits/stdc++.h> using namespace std; void permute(string a, int l, int r) { if (l == r) cout<<a<<endl; else { for (int i = l; i <= r; i++) { swap(a[l], a[i]); permute(a, l+1, r);swap(a[l], a[i]); } } } int main() { string str; cin>>str; int n = str.size(); permute(str, 0, n-1); return 0; } //end
Question 4:
Bastin once had trouble finding the numbers in a string. The numbers are distributed in a string across various test cases. There are various numbers in each test case you need to find the number in each test case. Each test case has various numbers in sequence. You need to find only those numbers which do not contain 9. For eg, if the string contains “hello this is alpha 5051 and 9475”.You will extract 5051 and not 9475. You need only those numbers which are consecutive and you need to help him find the numbers. Print the largest number.
Note: Use long long for storing the numbers from the string.
Input Format :
The first line consists of T test cases and next T lines contain a string.
Output Format:
For each string output the number stored in that string if various numbers are there print the largest one. If a string has no numbers print -1.
Constraints:
1 ≤ T ≤ 100
1 ≤ |S| ≤ 10000
Sample Input:
1
This is alpha 5057 and 97
Sample Output:
5057
Solution:
//codewindow.in #include<bits/stdc++.h> using namespace std; int main() { int t; cin >> t; cin.ignore(); while(t--) { string s; getline(cin, s); int n = s.length(); int n9 = 0; string res="", num = ""; for(int i = 0; i < n; i++) { n9 = 0; num = ""; while(s[i] >= '0' && s[i] <= '9') { if(s[i] == '9') n9 = 1; num = num + s[i]; i++; } if(!n9 && num != "") { long long a = stoll(num); long long b = -1; if(res != "") b = stoll(res); if(a> b) res = num; } } if(res == "") cout << "-1"; else cout <<res << endl; } return 0 //end
Follow Us
Also Checkout
- Unlocking Innovation and Diversity: Accenture HackDiva Empowers Women in Tech with Cutting-Edge Solutions – codewindow.in
- QA Engineer Opportunities at Siemens Company: Apply Now – codewindow.in
- QA Engineer Opportunities at Siemens Company: Apply Now – codewindow.in
- Software Engineer Positions at Siemens Company: Apply Now – codewindow.in
- Cloud Engineer II Opportunities at Insight Company: Apply Now – codewindow.in
- Shape Your Career: Assistant Engineer Opportunities at Jindal Company – codewindow.in
- Shape Your Future: Executive Opportunities at Jindal Company – cdewindow.in
- Associate Engineer, Software Development at Ingram: Apply Now – codewindow.in
- Jade Company’s UI/UX Development Engineer Opportunities – Apply Now – codewindow.in
- Transform Your Career with S&P Global: Apply for the Software Development Engineer Role and Lead the Future of Financial Technology Innovation – codewindow.in
- Unlock Your Potential at Accenture as an Associate Software Engineer – Elevate Your Career with Innovation and Excellence – codewindow.in
- Accelerate Your Career: Join NVIDIA’s Elite Software Engineering Internship Program and Shape the Future of Technology – codewindow.in
- C Programming Interview Questions – codewindow.in
- Lead the Way in Analytics: Specialist Position at Razorpay – codewindow.in
- Innovate with Cyient: Junior Software Engineer Wanted – codewindow.in
- Innovate with Volvo: Associate Software Engineer Wanted – codewindow.in
- Lead the Tech Revolution: Full Stack Developer at Unisys – codewindow.in
- Software Engineer at ABB: Unlock Innovation and Shape the Future – codewindow.in
- IBM Associate Systems Engineer Job: Boost Your Career with a Leading Technology Giant – codewindow.in
- Make Your Mark in Android Development: Join Concentrix – codewindow.in
- Infosys is Growing: Field Services Developer Role Now Open – codewindow.in
- Start Your IT Career Journey with Amazon: IT Services Support Associate I Opportunity – codewindow.in
- Shape the Future of Web: Front-End Software Engineer Opportunity at Google Cloud – codewindow.in
- Barclays QA Team Expands: QA Analyst Role Now Open- codewindow.in
- Eurofins QA Team Grows: Test Engineer Role Now Open – codewindow.in
- Exciting Opportunity: Java Spring Boot Senior Developer Role at Infosys – codewindow.in
- Unlock Your Potential at Nokia: Software Engineer Opportunities Await – codewindow.in
- Join Microsoft’s World-Class Team as a Software Engineer and Shape the Future of Technology – codewindow.in
- Virtusa is Seeking Talented React JS Developers to Drive Digital Excellence – codewindow.in
- Join IBM Dynamic Team as a Full Stack Developer and Shape the Future – codewindow.in
- EY Welcomes Aspiring AI/ML Interns to Unlock the Future of -codewindow.in
- Exciting Opportunity: Project Engineer at Rockwell Automation- codewindow.in
- Be at the Nexus of Technology & Finance: Associate Software Engineer at Goldman Sachs – codewindow.in
- Wipro is Hiring Test Engineers to Elevate Quality Assurance – codewindow.in
- Deloitte Is Hiring: Analysts and Senior Analysts Wanted to Drive Innovation – codewindow.in
- Exciting Software Development Opportunity At Oracle – codewindow.in
- BlackBerry Hiring System Software Developer – off campus – codewindow.in
- Lenskart hiring IT Support – off campus – codewindow.in
- Bold Hiring Software Engineer-UI – codewindow.in
- Myntra Hiring Software Engineer – off campus drive – codewindow.in
- PayPal Hiring Data Analyst 1 – codewindow.in
- SIEMENS HEALTHINEERS Hiring Data Scientist ( ML & AI) – codewindow.in
- RELX Digital hiring Software Engineer I – codewindow.in
- KPMG hiring Full Stack Developer Analyst – codewindow.in
- KPMG Hiring for Software Engineer – off Campus – codewindow.in
- Previous Year Coding Questions Suggestion Paper – codewindow.in
- Programming in C++ – codewindow.in
- Programming in C++ – codewindow.in
- Unstop Hiring Challenges Internships and Hackathons – codewindow.in
- Programming in Python – codewindow.in
- January 2024
- October 2023
- September 2023
- August 2023
- July 2023
- June 2023
- May 2023
- April 2023
- March 2023
- February 2023
- January 2023
- November 2022
- October 2022
- September 2022
- August 2022
- July 2022
- June 2022
- May 2022
- April 2022
- March 2022
- February 2022
- January 2022
- December 2021
- November 2021
- October 2021
- September 2021
- August 2021
- July 2021
- June 2021
- May 2021
- April 2021
- March 2021
- January 2021
- December 2020
- November 2020
- October 2020
- September 2020