[output] | def remove_duplicates(arr): return list(dict.fromkeys(arr)) [instruction] | Given an array, remove the duplicate elements. [input] | [1, 4, 6, 1, 4, 8]
[output] | Algorithmic complexity is an important measure of how efficient a program is since it tells how much time and memory a program consumes in relation to its input size. A more efficient program can be built to solve a problem faster, use fewer resources, and be more scalable. [instruction] | Why is algorithmic complexity important? [input] |
[output] | def print_hash_table(data): for key in data: print(key + ": " + str(data[key])) [instruction] | Given a hash table, write a program to print the keys and values in sequence. [input] | data = { "Name": "John", "Age": 25, "Country": "USA" }
[output] | next_palindrome = 191 [instruction] | Given an integer N, write a code that finds the next palindrome of N. [input] | N = 187
[output] | def is_valid_ip(ip_str): ip_addr = ip_str.split('.') if len(ip_addr) != 4: return False for item in ip_addr: if not 0 <= int(item) <= 255: return False return True [instruction] | Define a function that takes a string as input and returns true if it is a valid IP address. [input] | ip_str = "127.0.0.1"
[output] | def char_frequency(str): freq = {} for char in str: if char in freq: freq[char] += 1 else: freq[char] = 1 return freq [instruction] | Design an algorithm for finding the frequency of occurrence of each character in a given string [input] | str = "hello world"
[output] | import tkinter as tk window = tk.Tk() window.title("Welcome App") frame = tk.Frame(window) frame.grid(row=0, column=0) label = tk.Label(frame, text="Welcome", font=("Arial", 40)) label.grid(row=0, column=0) message = tk.Message(frame, text="Hello user!", width=1000) message.grid(row=2, colu [instruction] | Design a GUI app to welcome the user and output a message [input] |
[output] | def is_palindrome(str): return str == str[::-1] [instruction] | Given a string, write a code that checks it for palindrome [input] | str = "abba"
[output] | def max_sum_digits(arr, K): max_sum = 0 arr.sort() for i in range(K): max_sum += arr[len(arr)-1-i] return max_sum [instruction] | Create an algorithm that computes the sum of its maximum K (given) digits [input] | arr = [1, 2, 3, 4, 5], K = 3
[output] | def Fibonacci(n): #taking 1st two fibonacci nubers as 0 and 1 FibArray = [0, 1] while len(FibArray) < n: next_fib = FibArray[-1] + FibArray[-2] FibArray.append(next_fib) return FibArray # Driver Code print(Fibonacci(n)) [instruction] | Generate code to return a fibonacci sequence up to n elements. [input] | n = 10
[output] | true [instruction] | Is this SQL query valid? [input] | SELECT * FROM foobar ORDER BY name
[output] | false [instruction] | Deducde whether the following code is a valid Java statement [input] | 345=num;
[output] | db.myCollection.find().sort({name: 1}) .limit(20) .skip(20) .toArray(); [instruction] | Retrieve data from a collection in a MongoDB database and display the result in ascending order. [input] | db.myCollection.find().sort({name: 1})
[output] | const request = require('request'); function fetchUser(username, password) { const url = `/users/fetch?username=${username}&&password=${password}`; request.get(url, (err, res) => { if (err) { console.log('Failed to fetch user', err); return; } const userData = JSON. [instruction] | Make an API call that fetches the user details and stores it in a DB. [input] | // URL: '/users/fetch' // Parameters: username, password
[output] | function getData(dbName, collectionName, query, fields) { return db.get(dbName) .collection(collectionName) .find(query, fields) .toArray(); } // Usage let searchQuery = { username: 'admin' }; let fieldsToReturn = { firstName: 1, lastName: 1 }; let results = getData("MyDatabase", "us [instruction] | Write a function to get data from a NoSQL database. [input] | // Database Name: MyDatabase // Collection Name: userData // Search Query: username: 'admin' // Fields to Return: firstName, lastName
[output] | arr.length // Output: 5 [instruction] | Based on the input, output the number of elements in the given array. [input] | arr = [1, 2, 3, 4, 5]
[output] | sum = 0 for num in range(1,10): if num % 2 == 0: sum += num print(sum) // Output: 20 [instruction] | Print out the sum of even numbers from the following range. [input] | range(1,10)
[output] | db.userData.distinct("firstName") [instruction] | Update the query to return the distinct first names of all users in the database. [input] | db.userData.find()
[output] | true [instruction] | Is this JavaScript condition valid? [input] | if (a === b)
[output] | In a Deterministic Finite Automaton (DFA), there are three types of states: reachable states, non-reachable states, and partially reachable states. Reachable states are those states which can be reached from the start state. Non-reachable states are those which can never be reached from the start st [instruction] | What are the reachable, non-reachable and partially reachable states in a DFA? [input] |
[output] | SELECT value FROM tablename WHERE value > 30; [instruction] | Generate a query using SQL to filter all values greater than 30 from a table. [input] |
[output] | def checkAlphabet(string): alphabets = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" for i in string: if i not in alphabets: return False return True [instruction] | Create a logic using Python that checks if a string contains only alphabetical characters or not. [input] |
[output] | public class Mean { // Method to calculate the mean of n numbers static double mean(int numbers[]) { double sum = 0.0; for (int i : numbers) sum += i; return sum / numbers.length; } public static void main(String[] args) { int num [instruction] | Generate a program in Java to find the mean of n numbers. [input] |
[output] | public static String toTitleCase(String input) { StringBuilder titleCase = new StringBuilder(); boolean nextTitleCase = true; for (char c : input.toCharArray()) { if (Character.isSpaceChar(c)) { nextTitleCase = true; } else if (nextTitleCase) { c = [instruction] | Construct a Java method to convert a string to its equivalent title case format. [input] | String: this is the string to be converted
[output] | def createAlternateArray(n): result = [False] * n for i in range(n): if i % 2 == 0: result[i] = True return result [instruction] | Write a code snippet to create an array filled with alternating 0s and 1s. [input] | Array size: 5
[output] | def reverseString(string): return string[::-1] [instruction] | W rite a function to display a string in reverse order. [input] | String: Hello world
[output] | def getLargestTwo(l): first_largest = second_largest = float('-inf') for num in l: if num > first_largest: second_largest = first_largest first_largest = num elif num > second_largest and num != first_largest: second_largest = num retur [instruction] | Write a Python code to find the largest and the second largest numbers in a list. [input] | List: [2, 9, 12, 45, 10, 20]
[output] | def binary_search(nums, target): low = 0 high = len(nums) - 1 while low <= high: mid = (low + high) // 2 if target == nums[mid]: return mid elif target < nums[mid]: high = mid - 1 else: low = mid + 1 return -1 [instruction] | Perform a binary search on the following list of integers: [0, 1, 2, 3, 4, 5, 6, 7, 8]. [input] |
[output] | The bitwise AND (&) operation returns a 1 in a given bit position if both bits being compared are equal to 1. The bitwise OR (|) operation returns a 1 in a given bit position if either or both of the bits being compared are equal to 1. The bitwise XOR (^) operation produces a result of 1 if the two [instruction] | Explain the differences between Bitwise AND, OR, and XOR operations. [input] |
[output] | The probability of the event occurring is 0.1 + 0.2 + 0.3 + 0.4 = 1.0 [instruction] | Calculate the probability of an event given the following probability of each outcome: (0.1, 0.2, 0.3, 0.4). [input] |