Coding Question 3

3 comments on “Coding Question 3”


  • Ashish

    comparatively easy :-
    import java.util.Scanner;
    public class findLeadersRoom {
    public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    // Read the size of each group (K)
    int K = scanner.nextInt();
    scanner.nextLine(); // Consume the newline character

    // Read the unordered list of room numbers
    String[] roomNumbers = scanner.nextLine().split(” “);

    // Initialize a variable to store the unique room number
    long uniqueRoomNumber = 0;

    // Iterate through the room numbers and perform XOR operation
    for (String roomNumber : roomNumbers) {
    long number = Long.parseLong(roomNumber);
    uniqueRoomNumber ^= number;
    }

    // Output the Group Leader’s room number
    System.out.println(uniqueRoomNumber);

    scanner.close();
    }
    }


  • NotSid

    #include
    using namespace std;

    int main()
    {
    map mpp;
    vectorarr;
    int num;
    do{
    cin>>num;
    arr.push_back(num);
    }while(num!=0);
    cout<<"done"<<endl;
    for(int i=0;i<arr.size();i++){
    mpp[arr[i]]++;
    }
    mpp.erase(0);
    for(auto it : mpp){
    cout<<it.first<<"—"<<it.second<<endl;
    }

    for(auto it : mpp){
    if(it.second == 1){
    cout<<it.first;
    }
    }
    return -1;
    }