US001- Editorial

Unique Sequence

PROBLEM LINK

https://www.codechef.com/CDHN2021/problems/US001

Author: Aman Nadaf

Tester: Aman Nadaf

Editorialist: Aman Nadaf

DIFFICULTY:

Cakewalk

PREREQUISITES:

Linear Search

PROBLEM:

A Unique Sequence is defined as a sequence that do not have any repeating elements in it.
You will be given any random sequence of integers, and you have to tell whether it is a Unique Sequence or not.

EXPLANATION:

So we had to take an array of size N (given) read the elements in array ,then traverse through the array and compare each element of the array with other using nested for loops, if there are identical elements (repeated elements) we print “ugly” otherwise we print “beautiful”.

SOLUTIONS:

Setter's Solution


#include <bits/stdc++.h>
#include <math.h>
using namespace std;

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define vll vector<long long int>

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    std::ios::sync_with_stdio(false);

    int t;
    cin >> t;
    while (t--)
    {
      	int n;
		cin>>n;
		int arr[n];
		bool ans = true;
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				if(arr[i] == arr[j]){
					ans = false;
				}
			}
		}
		if(ans == true){
			cout<<"beautiful"<<endl;
		}else{
			cout<<"ugly"<<endl;
		}

    }
}

Feel free to share your approach here. Suggestions are always welcomed. :slight_smile:
.