Back

Deloitte Coding Questions and Answers 2024: Important Topics

19 Dec 2024
10 min read

Deloitte is one of the largest multinational finance and professional services providers based in the UK. The company consistently seeks talented individuals across various fields. The hiring process at Deloitte is complex and influenced by numerous factors, including candidates' skills, education, and extensive technical knowledge. A significant component of this hiring process is the coding round, which assesses candidates' problem-solving abilities and programming proficiency. Whether you are preparing for a coding interview at Deloitte or familiarizing yourself with typical Deloitte coding questions, it’s essential to be thoroughly prepared.

Importance of coding rounds in Deloitte Recruitment

The coding round is an essential part of the Deloitte recruitment process as it evaluates a candidate's technical skills, logical thinking, and ability to solve complex problems. Usually, these questions are framed in a way that involves understanding a mix of fundamental programming concepts, data structures, algorithms, and practical applications. As a global leader in consulting, audit, and technology services, Deloitte focuses on ensuring that the candidates they hire possess not only strong technical capabilities but also an ability to think critically and apply these skills to real-world situations. So, if you’re planning for the Deloitte interview, then you must prepare for a technical coding round. 

In this article, we will discover comprehensive information about the top coding questions featured in Deloitte National Level Assessment coding questions, Technical Interviews, and other details on Deloitte Coding Questions and Answers.

Concepts to Look in Deloitte Coding Topics

Usually, the interview starts with some personal questions like - 

  • Why this company and role? 
  • Tell me something about yourself that you have not mentioned on the CV?

After two or three such questions, the coding round starts which is about 30 to 45 minutes. You will be given 3-5 coding questions and had to solve them in under 30 minutes.

Candidates can expect these topics in the Deloitte coding round:

Arrays

  • Searching, sorting, and manipulation
  • Subarrays and sub-sequences problems

Linked Lists

  • Reversal, cycle detection, merging lists
  • Problems involving n-th node from the end, deleting nodes

Stacks and Queues

  • Parentheses matching, stack-based algorithms
  • Implementing a queue using two stacks

Hashing

  • HashMap, HashSet applications
  • Frequency counting, anagram detection

Trees

  • Binary Search Tree (BST) operations
  • Tree traversals (pre-order, in-order, post-order)
  • Height of tree, finding Lowest Common Ancestor (LCA)

Graphs

  • Graph representation (adjacency list, matrix)

BFS and DFS

  • Shortest path algorithms (Dijkstra, Bellman-Ford)
  • Cycle detection in directed/undirected graphs

Top Coding Questions Asked in Deloitte 2024

Here are the coding questions asked in Deloitte:

Problem Statement 1: Given an array of integers, find the number of subarrays whose sum is odd. A subarray is defined as any contiguous portion of the array. You must count all subarrays where the sum of elements is odd.

Input

The first line contains an integer N (1 ≤ N ≤ 10^5), the size of the array.

The second line contains N integers, each between -1000 and 1000.

Output

Return the total number of subarrays with an odd sum.

Test Cases

Input Output
    5
    1 2 3 4 5
9
    3
    1 1 1
4

C Program

#include <stdio.h>
int main() {
    int N;
    scanf("%d", &N);
    int arr[N];
    for(int i = 0; i < N; i++) {
        scanf("%d", &arr[i]);
    }
    int odd_count = 0, even_count = 1, result = 0, prefix_sum = 0;

    for(int i = 0; i < N; i++) {
        prefix_sum += arr[i];
        if (prefix_sum % 2 == 0)
            result += odd_count;
        else
            result += even_count;
        
        if (prefix_sum % 2 == 0)
            even_count++;
        else
            odd_count++;
    }

    printf("%d\n", result);
    return 0;
}

C++ Program

#include <iostream>
#include <vector>
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> arr(N);
    for (int i = 0; i < N; i++) {
        cin >> arr[i];
    }

    int odd_count = 0, even_count = 1, result = 0, prefix_sum = 0;
    for (int i = 0; i < N; i++) {
        prefix_sum += arr[i];
        if (prefix_sum % 2 == 0)
            result += odd_count;
        else
            result += even_count;

        if (prefix_sum % 2 == 0)
            even_count++;
        else
            odd_count++;
    }

    cout << result << endl;
    return 0;
}

Problem Statement 2: Given a string, find the length of the longest palindromic substring. A palindromic string reads the same forwards and backward. You must implement an efficient solution to find this substring.

Input

A string S with a length between 1 and 1000.

Output

Output the length of the longest palindromic substring.

Test Cases

Input Output
Babad 3
cbbd 2

C Program

#include <stdio.h>
#include <string.h>
#define MAX 1001

int max(int a, int b) {
    return (a > b) ? a: b;
}

int expandAroundCenter(char *s, int left, int right) {
    while (left >= 0 && right < strlen(s) && s[left] == s[right]) {
        left--;
        right++;
    }
    return right - left - 1;
}

int main() {
    char s[MAX];
    scanf("%s", s);
    int len = strlen(s);
    int max_len = 1;
    for (int i = 0; i < len; i++) {
        max_len = max(max_len, expandAroundCenter(s, i, i));
        max_len = max(max_len, expandAroundCenter(s, i, i + 1));
    }
    printf("%d\n", max_len);
    return 0;
}

C++ Program

#include <iostream>
#include <string>
using namespace std;

int max(int a, int b) {
    return (a > b) ? a : b;
}

int expandAroundCenter(string s, int left, int right) {
    while (left >= 0 && right < s.length() && s[left] == s[right]) {
        left--;
        right++;
    }
    return right - left - 1;
}

int main() {
    string s;
    cin >> s;
    int len = s.length();
    int max_len = 1;
    for (int i = 0; i < len; i++) {
        max_len = max(max_len, expandAroundCenter(s, i, i));
        max_len = max(max_len, expandAroundCenter(s, i, i + 1));
    }
    cout << max_len << endl;
    return 0;
}

Problem Statement 3: Given k sorted arrays, merge them into a single sorted array. Implement the solution using a min-heap or priority queue for optimal performance.

Input

  • An integer k represents the number of arrays.
  • k arrays of integers where each array is sorted.

Output

  • Output the merged sorted array.

Test Cases

Input Output
    3
    1 4 7
    2 5 8
    3 6 9
1 2 3 4 5 6 7 8 9
    2
    1 3 5
    2 4 6
1 2 3 4 5 6

C Program

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

typedef struct {
    int value;
    int row;
    int col;
} Element;

int compare(const void *a, const void *b) {
    return ((Element *)a)->value - ((Element *)b)->value;
}

int main() {
    int k;
    scanf("%d", &k);
    int arr[k][1000], sizes[k];
    for (int i = 0; i < k; i++) {
        scanf("%d", &sizes[i]);
        for (int j = 0; j < sizes[i]; j++) {
            scanf("%d", &arr[i][j]);
        }
    }
    Element heap[k];
    int heap_size = 0;
    for (int i = 0; i < k; i++) {
        heap[heap_size].value = arr[i][0];
        heap[heap_size].row = i;
        heap[heap_size].col = 0;
         heap_size++;
    }

    qsort(heap, heap_size, sizeof(Element), compare);

    while (heap_size > 0) {
        Element min = heap[0];
        printf("%d ", min.value);
        if (min.col + 1 < sizes[min.row]) {
            heap[0].value = arr[min.row][min.col + 1];
            heap[0].col = min.col + 1;
            qsort(heap, heap_size, sizeof(Element), compare);
        } else {
            heap_size--;
            for (int i = 0; i < heap_size; i++) {
                heap[i] = heap[i + 1];
            }
        }
    }
    return 0;
}

C++ Program

#include <iostream>
#include <vector>
#include <queue>
using namespace std;

struct Element {
    int value;
    int row;
    int col;
};

class Compare {
public:
    bool operator()(Element a, Element b) {
        return a.value > b.value;
    }
};
int main() {
    int k;
    cin >> k;
    vector<vector<int>> arr(k);
    vector<int> sizes(k);

    for (int i = 0; i < k; i++) {
        cin >> sizes[i];
        arr[i].resize(sizes[i]);
        for (int j = 0; j < sizes[i]; j++) {
            cin >> arr[i][j];
        }
    }

    priority_queue<Element, vector<Element>, Compare> minHeap;
    for (int i = 0; i < k; i++) {
        minHeap.push({arr[i][0], i, 0});
    }

    while (!minHeap.empty()) {
        Element min = minHeap.top();
        minHeap.pop();
        cout << min.value << " ";
        
        if (min.col + 1 < sizes[min.row]) {
            minHeap.push({arr[min.row][min.col + 1], min.row, min.col + 1});
        }
    }
    cout << endl;
    return 0;
}

Problem Statement 4: Given an unsorted array of integers, find the kth largest element in the array. You need to solve the problem efficiently, without sorting the array, using a priority queue (min-heap) or quick select algorithm.

Input

  • The first line contains two integers, N (size of array) and k.
  • In the second line, there are N integers representing the array elements.

Output

  • Output the kth largest element in the array.

Test cases

Input Output
    6 2
    3 2 1 5 6 4
5
    5 1
    1 2 3 4 5
5

C Program

#include <stdio.h>
#include <stdlib.h>

int compare(const void *a, const void *b) {
    return *(int*)b - *(int*)a;
}

int main() {
    int N, k;
    scanf("%d %d", &N, &k);
    int arr[N];
    for (int i = 0; i < N; i++) {
        scanf("%d", &arr[i]);
    }
    
    qsort(arr, N, sizeof(int), compare);
    printf("%d\n", arr[k-1]);
    return 0;
}

C++ Program

#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main() {
    int N, k;
    cin >> N >> k;
    vector<int> arr(N);
    for (int i = 0; i < N; i++) {
        cin >> arr[i];
    }

    priority_queue<int, vector<int>, greater<int>> minHeap;
    for (int i = 0; i < N; i++) {
        minHeap.push(arr[i]);
        if (minHeap.size() > k) {
            minHeap.pop();
        }
    }

    cout << minHeap.top() << endl;
    return 0;
}
₹ 49,000
strip
₹ 33,000
/-
Karthik was able to transform his career from a boring job to an exciting job in software!
Talk to a career expert
intensive student
emoji

Problem Statement 5: An inversion in an array is a pair of indices i and j such that i < j and arr[i] > arr[j]. Given an array, count the number of inversions in the array. You need to implement an efficient solution with a time complexity better than O(n^2).

Input

  • The first line contains an integer N (1 ≤ N ≤ 10^5), the size of the array.
  • In the second line, there are N integers representing the array elements.

Output

Return the count of inversions in the array.

Test Cases

Input Output
    5
    2 3 8 6 1
5
    3
    1 2 3
0

C Program

#include <stdio.h>

int merge_and_count(int arr[], int temp[], int left, int right) {
    int mid, inv_count = 0;
    if (left < right) {
        mid = (left + right) / 2;
        inv_count += merge_and_count(arr, temp, left, mid);
        inv_count += merge_and_count(arr, temp, mid + 1, right);
        inv_count += merge(arr, temp, left, mid, right);
    }
    return inv_count;
}

int merge(int arr[], int temp[], int left, int mid, int right) {
    int i = left, j = mid + 1, k = left, inv_count = 0;
    while (i <= mid && j <= right) {
        if (arr[i] <= arr[j]) {
            temp[k++] = arr[i++];
        } else {
            temp[k++] = arr[j++];
            inv_count += (mid - i + 1);
        }
    }
    while (i <= mid) {
        temp[k++] = arr[i++];
    }
    while (j <= right) {
        temp[k++] = arr[j++];
    }
    for (i = left; i <= right; i++) {
        arr[i] = temp[i];
    }
    return inv_count;
}

int main() {
    int N;
    scanf("%d", &N);
    int arr[N], temp[N];
    for (int i = 0; i < N; i++) {
        scanf("%d", &arr[i]);
    }
    printf("%d\n", merge_and_count(arr, temp, 0, N - 1));
    return 0;
}

C++ Program

#include <iostream>
#include <vector>
using namespace std;

long long merge_and_count(vector<int>& arr, vector<int>& temp, int left, int right) {
    long long inv_count = 0;
    if (left < right) {
        int mid = (left + right) / 2;
        inv_count += merge_and_count(arr, temp, left, mid);
        inv_count += merge_and_count(arr, temp, mid + 1, right);
        inv_count += merge(arr, temp, left, mid, right);
    }
    return inv_count;
}

long long merge(vector<int>& arr, vector<int>& temp, int left, int mid, int right) {
    int i = left, j = mid + 1, k = left;
    long long inv_count = 0;
    while (i <= mid && j <= right) {
        if (arr[i] <= arr[j]) {
            temp[k++] = arr[i++];
        } else {
            temp[k++] = arr[j++];
            inv_count += (mid - i + 1);
        }
    }
    while (i <= mid) {
        temp[k++] = arr[i++];
    }
    while (j <= right) {
        temp[k++] = arr[j++];
    }
    for (int i = left; i <= right; i++) {
arr[i] = temp[i];
    }
    return inv_count;
}

int main() {
    int N;
    cin >> N;
    vector<int> arr(N), temp(N);
    for (int i = 0; i < N; i++) {
        cin >> arr[i];
    }
    cout << merge_and_count(arr, temp, 0, N - 1) << endl;
    return 0;
}

Problem Statement 6: Given an unsorted array of integers, find the length of the longest increasing subsequence (LIS). An increasing subsequence is a subsequence where all elements are sorted in increasing order. Implement an efficient solution.

Input

  • The first line contains an integer N (1 ≤ N ≤ 10^5).
  • In the second line, there are N integers representing the array elements.

Output

Return the length of the longest increasing subsequence.

Input Output
    6
    10 9 2 5 3 7
3
    8
    3 10 2 1 20
3

C Program

#include <stdio.h>
#include <stdlib.h>
int max(int a, int b) {
    return (a > b) ? a : b;
}

int LIS(int arr[], int N) {
    int lis[N];
    lis[0] = 1;

    for (int i = 1; i < N; i++) {
        lis[i] = 1;
        for (int j = 0; j < i; j++) {
            if (arr[i] > arr[j]) {
                lis[i] = max(lis[i], lis[j] + 1);
            }
        }
    }
    int max_len = 0;
    for (int i = 0; i < N; i++) {
        max_len = max(max_len, lis[i]);
    }
    return max_len;
}

int main() {
    int N;
    scanf("%d", &N);
    int arr[N];
    for (int i = 0; i < N; i++) {
        scanf("%d", &arr[i]);
    }
    printf("%d\n", LIS(arr, N));
    return 0;
}

C++ Program

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int LIS(const vector<int>& arr, int N) {
vector<int> lis(N, 1);
    for (int i = 1; i < N; i++) {
        for (int j = 0; j < i; j++) {
            if (arr[i] > arr[j]) {
                lis[i] = max(lis[i], lis[j] + 1);
            }
        }
    }
    return *max_element(lis.begin(), lis.end());
}

int main() {
    int N;
    cin >> N;
    vector<int> arr(N);
    for (int i = 0; i < N; i++) {
        cin >> arr[i];
    }
    cout << LIS(arr, N) << endl;
    return 0;
}

Problem Statement 7: Given an array arr[] of size n, the task is to find the maximum sum of a subarray that can be obtained by deleting at most one element from the array. This is an extension of Kadane’s Algorithm.

Input

  • An integer n represents the size of the array.
  • An array arr[] of n integers.

Output

Return the maximum sum of a subarray that can be obtained by deleting at most one element.

Test Cases

Input Output
arr[] = {1, -2, 0, 3} 4
arr[] = {1, -2, -2, 3} 3

C Program

#include <stdio.h>
#include <limits.h>

int maxSumAfterOneDeletion(int arr[], int n) {
    int max_sum = arr[0], sum_with_deletion = 0, prev_sum = 0;

    for (int i = 0; i < n; i++) {
        prev_sum = prev_sum + arr[i];
        sum_with_deletion = sum_with_deletion + arr[i];
        if (sum_with_deletion < prev_sum) {
            sum_with_deletion = prev_sum;
        }
        if (prev_sum < 0) {
            prev_sum = 0;
        }
        max_sum = (max_sum > sum_with_deletion) ? max_sum : sum_with_deletion;
    }
    return max_sum;
}

int main() {
    int arr[] = {1, -2, 0, 3};
    int n = sizeof(arr) / sizeof(arr[0]);
    printf("%d\n", maxSumAfterOneDeletion(arr, n));
    return 0;
}

C++ Program

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int maxSumAfterOneDeletion(vector<int>& arr) {
    int n = arr.size();
    int max_sum = arr[0], prev_sum = 0, sum_with_deletion = 0;

    for (int i = 0; i < n; i++) {
        prev_sum = max(arr[i], prev_sum + arr[i]);
        sum_with_deletion = max(sum_with_deletion + arr[i], prev_sum);
        max_sum = max(max_sum, sum_with_deletion);
    }

    return max_sum;
}

int main() {
    vector<int> arr = {1, -2, 0, 3};
    cout << maxSumAfterOneDeletion(arr) << endl;
    return 0;
}

Problem Statement 8: Given a singly linked list, you need to reverse it. Modify the list in place, without using any extra space (except for a few pointers). Implement a function that reverses the entire list and returns the new head of the list.

Input

  • A singly linked list.

Output

  • The linked list reversed
Input Output
a1 -> 2 -> 3 -> 4 -> NULL 4 -> 3 -> 2 -> 1 -> NULL
5 -> 10 -> 15 -> NULL 15 -> 10 -> 5 -> NULL

C Program

#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node* next;
};

void reverse(struct Node** head) {
    struct Node *prev = NULL, *current = *head, *next = NULL;
    while (current != NULL) {
        next = current->next;
        current->next = prev;
        prev = current;
        current = next;
    }
    *head = prev;
}

void printList(struct Node* head) {
    while (head != NULL) {
        printf("%d -> ", head->data);
        head = head->next;
    }
    printf("NULL\n");
}

int main() {
    struct Node* head = NULL;
    struct Node* newNode;
    newNode = (struct Node*)malloc(sizeof(struct Node));
    newNode->data = 1;
    newNode->next = head;
    head = newNode;
    
    newNode = (struct Node*)malloc(sizeof(struct Node));
    newNode->data = 2;
    newNode->next = head;
    head = newNode;

    printList(head);
    reverse(&head);
    printList(head);
    
    return 0;
}

C++ Program

#include <iostream>
using namespace std;

struct Node {
    int data;
    Node* next;
};

void reverse(Node*& head) {
    Node *prev = nullptr, *current = head, *next = nullptr;
    while (current != nullptr) {
        next = current->next;
        current->next = prev;
        prev = current;
        current = next;
    }
    head = prev;
}

void printList(Node* head) {
    while (head != nullptr) {
        cout << head->data << " -> ";
        head = head->next;
    }
    cout << "NULL" << endl;
}

int main() {
    Node* head = nullptr;
    Node* newNode = new Node{1, head};
    head = newNode;

    newNode = new Node{2, head};
    head = newNode;

    printList(head);
    reverse(head);
    printList(head);
    
    return 0;
}
₹ 49,000
strip
₹ 33,000
/-
Karthik was able to transform his career from a boring job to an exciting job in software!
Talk to a career expert
intensive student
emoji

Problem Statement 9: Write a function to generate the first n Fibonacci numbers.

Input

  • The user is prompted to enter the number n, which represents how many Fibonacci numbers should be generated.

Output

  • The program generates and displays the first n Fibonacci numbers.
Input Output
5 0 1 1 2 3
3 0 1 1

C Program

#include <stdio.h>

// Function to generate the first n Fibonacci numbers
void generateFibonacci(int n) {
    int first = 0, second = 1, next;
    
    if (n <= 0) {
        printf("Enter a positive integer.\n");
        return;
    }
    
    printf("Fibonacci series: ");
    
    // Print the first Fibonacci number
    printf("%d ", first);
    
    // Print the second Fibonacci number
    if (n > 1) {
        printf("%d ", second);
    }
    
    // Generate and print the rest of the Fibonacci series
    for (int i = 3; i <= n; i++) {
        next = first + second;
        printf("%d ", next);
        first = second;
        second = next;
    }
    
    printf("\n");
}
int main() {
    int n;
    printf("Enter the number of Fibonacci terms to generate: ");
    scanf("%d", &n);
    
    generateFibonacci(n);
    
    return 0;
}

C++ Program

#include <iostream>
using namespace std;

// Function to generate the first n Fibonacci numbers
void generateFibonacci(int n) {
    int first = 0, second = 1, next;
    
    if (n <= 0) {
        cout << "Enter a positive integer." << endl;
        return;
    }
    
    cout << "Fibonacci series: ";
    
    // Print the first Fibonacci number
    cout << first << " ";
    
    // Print the second Fibonacci number
    if (n > 1) {
        cout << second << " ";
    }
    
    // Generate and print the rest of the Fibonacci series
    for (int i = 3; i <= n; i++) {
        next = first + second;
        cout << next << " ";
        first = second;
        second = next;
    }
cout << endl;
}

int main() {
    int n;
    cout << "Enter the number of Fibonacci terms to generate: ";
    cin >> n;
    
    generateFibonacci(n);
    
    return 0;
}

Problem Statement 10: Write a function to check if a number is prime. Also, How can a number be expressed as a sum of two prime numbers?

Input

  • The user is prompted to enter a number num to check if it's prime.

Output

  • The program checks if the entered number is prime and displays the result.
Input Output
29 29 is a prime number
18 18 is not a prime number

C Program

#include <stdio.h>
#include <stdbool.h>

// Function to check if a number is prime
bool isPrime(int n) {
    if (n <= 1) {
        return false; // 0 and 1 are not prime numbers
    }
    
    // Check for factors from 2 to sqrt(n)
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            return false; // n is divisible by i, so it's not prime
        }
    }
    return true;
}

// Function to check if a number can be expressed as a sum of two prime numbers
void checkPrimeSum(int n) {
    printf("Checking if %d can be expressed as a sum of two primes:\n", n);
    
    for (int i = 2; i <= n / 2; i++) {
        if (isPrime(i) && isPrime(n - i)) {
            printf("%d = %d + %d\n", n, i, n - i);
            return; // Found a pair, exit the function
        }
    }
    printf("%d cannot be expressed as the sum of two prime numbers.\n", n);
}

int main() {
    int num;
    
    // Check if the number is prime
    printf("Enter a number to check if it's prime: ");
    scanf("%d", &num);
    
    if (isPrime(num)) {
        printf("%d is a prime number.\n", num);
    } else {
        printf("%d is not a prime number.\n", num);
    }
    
    // Check if the number can be expressed as the sum of two primes
    printf("Enter a number to check if it can be expressed as the sum of two primes: ");
    scanf("%d", &num);
    
    checkPrimeSum(num);
    
    return 0;
}

Problem Statement 11: You are developing a software feature for a plagiarism detection tool. One of the detection methods involves checking whether the content in two documents is simply a rearrangement of the same set of words, which could indicate potential plagiarism.

Write a function that takes two sentences as input and checks if they are sentence anagrams, meaning the sentences contain exactly the same words (ignoring order and case).

Input

  • The user is prompted to enter two sentences. The program will check if the two sentences are anagrams by removing punctuation and converting the characters to lowercase.

Output

  • The program checks if the two sentences are anagrams and displays the result.
Input Output
    Listen
    Silent
The sentences are anagrams.
    Hello
    World
The sentences are not anagrams.

C Program

#include <stdio.h>
#include <string.h>
#include <ctype.h>

// Function to clean and sort the words in a sentence
void cleanAndSort(char *sentence, char *result) {
    int j = 0;
    int len = strlen(sentence);
    
    // Remove punctuation and convert to lowercase
    for (int i = 0; i < len; i++) {
        if (isalpha(sentence[i]) || isspace(sentence[i])) { // Keep letters and spaces
            result[j++] = tolower(sentence[i]); // Convert to lowercase }
    }
    result[j] = '\0'; // Null-terminate the string

    // Sort the cleaned string
    for (int i = 0; i < j - 1; i++) {
        for (int k = i + 1; k < j; k++) {
            if (result[i] > result[k]) {
                char temp = result[i];
                result[i] = result[k];
                result[k] = temp;
            }
        }
    }
}

// Function to check if two sentences are anagrams
int areSentencesAnagrams(char *sentence1, char *sentence2) {
    char cleaned1[1000], cleaned2[1000];

    // Clean and sort the sentences
    cleanAndSort(sentence1, cleaned1);
    cleanAndSort(sentence2, cleaned2);

    // Compare the cleaned and sorted versions
    return strcmp(cleaned1, cleaned2) == 0;
}

int main() {
    char sentence1[1000], sentence2[1000];

    // Input two sentences
    printf("Enter the first sentence: ");
    fgets(sentence1, sizeof(sentence1), stdin);
    printf("Enter the second sentence: ");
    fgets(sentence2, sizeof(sentence2), stdin);

    // Remove newline character from fgets input
    sentence1[strcspn(sentence1, "\n")] = '\0';
    sentence2[strcspn(sentence2, "\n")] = '\0';

    // Check if sentences are anagrams
    if (areSentencesAnagrams(sentence1, sentence2)) {
 printf("The sentences are anagrams.\n");
    } else {
        printf("The sentences are not anagrams.\n");
    }

    return 0;
}

C++ Program

#include <iostream>
#include <cstring>
#include <cctype>
#include <algorithm>  // For std::sort

// Function to clean and sort the words in a sentence
void cleanAndSort(const char *sentence, char *result) {
    int j = 0;
    int len = strlen(sentence);
    
    // Remove punctuation and convert to lowercase
    for (int i = 0; i < len; i++) {
        if (isalpha(sentence[i]) || isspace(sentence[i])) { // Keep letters and spaces
            result[j++] = tolower(sentence[i]); // Convert to lowercase
        }
    }
    result[j] = '\0'; // Null-terminate the string

    // Sort the cleaned string
    std::sort(result, result + j); // Using C++'s built-in sort
}

// Function to check if two sentences are anagrams
bool areSentencesAnagrams(const char *sentence1, const char *sentence2) {
    char cleaned1[1000], cleaned2[1000];
    // Clean and sort the sentences
    cleanAndSort(sentence1, cleaned1);
    cleanAndSort(sentence2, cleaned2);
    
    // Compare the cleaned and sorted versions
    return strcmp(cleaned1, cleaned2) == 0;
}
int main() {
    char sentence1[1000], sentence2[1000];
    
    // Input two sentences
    std::cout << "Enter the first sentence: ";
    std::cin.getline(sentence1, sizeof(sentence1));
    std::cout << "Enter the second sentence: ";
    std::cin.getline(sentence2, sizeof(sentence2));
    
    // Check if sentences are anagrams
    if (areSentencesAnagrams(sentence1, sentence2)) {
        std::cout << "The sentences are anagrams.\n";
    } else {
        std::cout << "The sentences are not anagrams.\n";
    }

    return 0;
}

Conclusion

In conclusion, Deloitte's coding round plays a crucial role in identifying top talent for the company. By mastering key concepts such as data structures, algorithms, and problem-solving techniques, you can significantly improve your chances of success in the Deloitte coding interview. Remember, practicing coding questions on platforms leetcoode,codechef and hackerrank to clear the assessment round. Preparing these Deloitte coding questions and answers sharpens your problem-solving skills, and it will be key to performing well in the recruitment process.

₹ 49,000
strip
₹ 33,000
/-
Karthik was able to transform his career from a boring job to an exciting job in software!
Talk to a career expert
intensive student
emoji

Frequently Asked Questions

1.  Does Deloitte have coding questions?

Yes, Deloitte does ask coding questions during technical interviews, especially for software development roles. These questions typically focus on problem-solving, algorithms, data structures, and sometimes system design.

2. Which company has the hardest coding interview questions?

The difficulty of coding interview questions can vary depending on the role, but some of the companies known for having particularly challenging coding interviews include:

  • Google
  • Facebook (Meta)
  • Amazon
  • Microsoft
  • Netflix
  • Apple

These companies often ask complex algorithmic and data structure questions, as well as design problems.

3. Does Deloitte ask DSA questions?

Yes, Deloitte does ask questions about data structures and algorithms (DSA). These are a key part of the interview process for technical roles, focusing on problem-solving skills using different data structures like arrays, trees, graphs, and algorithms such as sorting, searching, and dynamic programming.

4. Is the Deloitte interview easy to crack?

The difficulty of a Deloitte interview depends on various factors such as the role, your preparation, and your experience. While it may not be as tough as some tech giants like Google or Facebook, Deloitte's technical interviews still require solid understanding and problem-solving skills, especially in coding and DSA. A good preparation strategy and understanding of key concepts can make it easier to crack.

5. What are some common Deloitte coding questions for freshers?

Freshers can expect basic questions on arrays, strings, and searching algorithms such as binary search and linear search.

6. How can I prepare for Deloitte NLA coding questions?

For Deloitte National Level Assessment coding questions, focus on mastering advanced algorithms and problem-solving techniques. Practice on competitive coding platforms and review previous year's questions.

Read More Articles

Chat with us
Chat with us
Talk to career expert