give the most common coding interview questions asked for computer science students with…
- User
give the most common coding interview questions asked for computer science students with answers in pseudocode
- Assistant
- Reverse a string: Q: Write a function that takes in a string and returns the reverse of that string.
A:
pythonfunction reverseString(str): reversedStr = "" for i in range(len(str)-1, -1, -1): reversedStr += str[i] return reversedStr- Find the largest number in an array: Q: Write a function that takes in an array of integers and returns the largest number in the array.
A:
cppfunction findLargestNumber(arr): largestNumber = arr[0] for i in range(1, len(arr)): if arr[i] > largestNumber: largestNumber = arr[i] return largestNumber- Fibonacci sequence: Q: Write a function that takes in a number n and returns the nth number in the Fibonacci sequence.
A:
cppfunction fibonacci(n): if n == 0 or n == 1: return n else: return fibonacci(n-1) + fibonacci(n-2)- Binary search: Q: Write a function that performs a binary search on a sorted array and returns the index of the searched value.
A:
vbnetfunction binarySearch(arr, value): low = 0 high = len(arr) - 1 while low <= high: mid = (low + high) // 2 if arr[mid] == value: return mid elif arr[mid] < value: low = mid + 1 else: high = mid - 1 return -1- Reverse a linked list: Q: Write a function that takes in the head of a linked list and returns the linked list in reverse order.
A:
javafunction reverseLinkedList(head): previousNode = null currentNode = head while currentNode != null: nextNode = currentNode.next currentNode.next = previousNode previousNode = currentNode currentNode = nextNode return previousNode - User
give me more of these
- Assistant
Sure, here are five more common coding interview questions with answers in pseudocode:
- User
give me more of these
- Assistant
- User
give me of these on the topic of database queries
- Assistant
Sure, here are five common database query interview questions with answers:
- Write a SQL query to get the second highest salary from an employee table: Q: Write a SQL query to get the second highest salary from an employee table.
A:
sqlSELECT MAX(salary) FROM employee WHERE salary < (SELECT MAX(salary) FROM employee);- Write a SQL query to count the number of occurrences of each type of car in a car table: Q: Write a SQL query to count the number of occurrences of each type of car in a car table.
A:
vbnetSELECT car_type, COUNT(*) as count FROM car GROUP BY car_type;- Write a SQL query to get the top 5 most common last names from a customer table: Q: Write a SQL query to get the top 5 most common last names from a customer table.