- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 Articles
- Java program to check whether a given string is Heterogram or not
- Python 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
- C program to check if a given string is Keyword or not?
- C++ Program to Check Whether a Number is Prime or Not
- C++ Program to Check Whether a Number is Palindrome or Not
- C# program to check whether a list is empty or not
- C Program to Check Whether a Number is Prime or not?
- C++ Program to Check Whether a Character is Alphabet or Not
- C++ Program to Check Whether a given Binary Tree is a Full Binary Tree or not
- Program to check whether the given number is Buzz Number or not in C++
- Program to check whether given words are maintaining given pattern or not in C++
- C# Program to check whether a node is a LinkedList or not
- Python Program to Check Whether a String is a Palindrome or not Using Recursion

Advertisements