📜 ⬆️ ⬇️

Issue # 20: IT training - current issues and challenges from leading companies

We continue to publish interesting tasks and questions from interviews in various IT-companies of the world.

KDPV
This time there were questions for future software engineers in Symantec. On the eve of the May holidays, the tasks chosen are not the most difficult, but require some thought. Please also write in the comments interesting questions and tasks that you met during the interviews.

Questions


  1. Counterfeit coins
    It is a box containing coin coins. The tail is 17/20. Find the value of 'n'.

    Transfer
    There are n coins in a box, 7 of which are fake - with tails on both sides, and the rest are correct. If you select and flip a coin out of the box - the chance of tailing 17/20. Find n.

  2. The largest unavailable number
    At McDonald's you can order and you can not order it at all?

    Transfer
    At McDonalds you can order chicken nuggets in a box for 6, 9 and 20 pcs. What is the maximum number of nuggets that cannot be ordered with any combination of these boxes?
    Note No, we did not pay advertising :)


Tasks


  1. Find all combinations
    It can be formed from the set.

    Examples:
    ')
    Input:
    set [] = {'a', 'b'}, k = 3

    Output:
    a
    b
    aa
    ab
    ba
    bb
    aaa
    aab
    aba
    abb
    baa
    bab
    bba
    bbb

    Input:
    set [] = {'a', 'b', 'c', 'd'}, k = 1
    Output:
    a
    b
    c
    d

    Transfer
    Given a set of characters and a positive number k. Print all possible string combinations from 1 to k that can be obtained from this set.

    Examples:

    Entrance:
    set [] = {'a', 'b'}, k = 3

    Output:
    a
    b
    aa
    ab
    ba
    bb
    aaa
    aab
    aba
    abb
    baa
    bab
    bba
    bbb

    Entrance:
    set [] = {'a', 'b', 'c', 'd'}, k = 1
    Output:
    a
    b
    c
    d

  2. Delete a node in a single-linked list
    This is a singly linked list, delete the node. Note. Write a program to accomplish the task, pseudocode is accepted.

    Transfer
    Given a pointer to a single-linked list item, you must delete this item Please note that the pointer to the head element is not given. Write a program that performs the task, pseudocode is acceptable.

  3. Comment remover
    Write a C / C ++ code.

    Transfer
    Write a program that removes comments from C / C ++ code.

Answers will be given within the next week - have time to decide. Good luck!

Solutions


  1. Question 1
    The correct answer is 10, which was quickly calculated.

  2. Question 2
    43. The correct answer was given in the first comment and explained in the discussion in this thread.

  3. Task 1
    Solution option:
    // C# program to print all // possible strings of length k using System; class GFG { // The method that prints all // possible strings of length k. // It is mainly a wrapper over // recursive function printAllKLengthRec() static void printAllKLength(char[] set, int k) { int n = set.Length; for (int j=0; j<=k; j++) { printAllKLengthRec(set, "", n, j); } } // The main recursive method // to print all possible // strings of length k static void printAllKLengthRec(char[] set, String prefix, int n, int k) { // Base case: k is 0, // print prefix if (k == 0) { Console.WriteLine(prefix); return; } // One by one add all characters // from set and recursively // call for k equals to k-1 for (int i = 0; i < n; ++i) { // Next character of input added String newPrefix = prefix + set[i]; // k is decreased, because // we have added a new character printAllKLengthRec(set, newPrefix, n, k - 1); } } // Driver Code static public void Main () { Console.WriteLine("First Test"); char[] set1 = {'a', 'b'}; int k = 3; printAllKLength(set1, k); Console.WriteLine("\nSecond Test"); char[] set2 = {'a', 'b', 'c', 'd'}; k = 1; printAllKLength(set2, k); } } 


  4. Task 2
    The correct approach to the solution suggested Andy_U in this comment . Code:
     #include<stdio.h> #include<assert.h> #include<stdlib.h> /* Link list node */ struct Node { int data; struct Node* next; }; /* Given a reference (pointer to pointer) to the head of a list and an int, push a new node on the front of the list. */ void push(struct Node** head_ref, int new_data) { /* allocate node */ struct Node* new_node = (struct Node*) malloc(sizeof(struct Node)); /* put in the data */ new_node->data = new_data; /* link the old list off the new node */ new_node->next = (*head_ref); /* move the head to point to the new node */ (*head_ref) = new_node; } void printList(struct Node *head) { struct Node *temp = head; while(temp != NULL) { printf("%d ", temp->data); temp = temp->next; } } void deleteNode(struct Node *node_ptr) { struct Node *temp = node_ptr->next; node_ptr->data = temp->data; node_ptr->next = temp->next; free(temp); } /* Drier program to test above function*/ int main() { /* Start with the empty list */ struct Node* head = NULL; /* Use push() to construct below list 1->12->1->4->1 */ push(&head, 1); push(&head, 4); push(&head, 1); push(&head, 12); push(&head, 1); printf("Before deleting \n"); printList(head); /* I m deleting the head itself. You can check for more cases */ deleteNode(head); printf("\nAfter deleting \n"); printList(head); getchar(); return 0; } 


  5. Task 3
    Solution option:
     // C++ program to remove comments from a C/C++ program #include <iostream> using namespace std; string removeComments(string prgm) { int n = prgm.length(); string res; // Flags to indicate that single line and multpile line comments // have started or not. bool s_cmt = false; bool m_cmt = false; // Traverse the given program for (int i=0; i<n; i++) { // If single line comment flag is on, then check for end of it if (s_cmt == true && prgm[i] == '\n') s_cmt = false; // If multiple line comment is on, then check for end of it else if (m_cmt == true && prgm[i] == '*' && prgm[i+1] == '/') m_cmt = false, i++; // If this character is in a comment, ignore it else if (s_cmt || m_cmt) continue; // Check for beginning of comments and set the approproate flags else if (prgm[i] == '/' && prgm[i+1] == '/') s_cmt = true, i++; else if (prgm[i] == '/' && prgm[i+1] == '*') m_cmt = true, i++; // If current character is a non-comment character, append it to res else res += prgm[i]; } return res; } // Driver program to test above functions int main() { string prgm = " /* Test program */ \n" " int main() \n" " { \n" " // variable declaration \n" " int a, b, c; \n" " /* This is a test \n" " multiline \n" " comment for \n" " testing */ \n" " a = b + c; \n" " } \n"; cout << "Given Program \n"; cout << prgm << endl; cout << " Modified Program "; cout << removeComments(prgm); return 0; } 


Source: https://habr.com/ru/post/354684/


All Articles