

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# program to check whether a given string is Heterogram or not
Heterogram for a string means the string isn’t having duplicate letters. For example −
Mobile Cry Laptop
Loop through each word of the string until the length of the string −
for (int i = 0; i < len; i++) { if (val[str[i] - 'a'] == 0) val[str[i] - 'a'] = 1; else return false; }
Above, len is the length of the string.
Let us see the complete code −
Example
using System; public class GFG { static bool checkHeterogram(string str, int len) { int []val = new int[26]; for (int i = 0; i < len; i++) { if (val[str[i] - 'a'] == 0) val[str[i] - 'a'] = 1; else return false; } return true; } public static void Main () { string str = "mobile"; // length of the entered string int len = str.Length; if(checkHeterogram(str, len)) Console.WriteLine("String is Heterogram!"); else Console.WriteLine("String is not a Heterogram!"); } }
Output
String is Heterogram!
- Related Questions & Answers
- Python program to check whether a given string is Heterogram or not
- Java program to check whether a given string is Heterogram or not
- C++ program to check whether given string is bad or not
- C++ Program to check whether given password is strong or not
- Program to check whether given graph is bipartite or not in Python
- C program to check if a given string is Keyword or not?
- Python program to check if a given string is Keyword or not
- Python Program to Check Whether a String is a Palindrome or not Using Recursion
- Write a Golang program to check whether a given number is a palindrome or not
- Write a Golang program to check whether a given number is prime number or not
- Program to check given string is pangram or not in Python
- Program to check whether given matrix is Toeplitz Matrix or not in Python
- Program to check whether given number is Narcissistic number or not in Python
- Program to check whether given tree is symmetric tree or not in Python
- C# program to check whether a list is empty or not
Advertisements