[output] | SELECT * FROM table_name GROUP BY col1, col2, ... HAVING COUNT(*) > 1 [instruction] | Write a SQL query which returns rows that have duplicate values in one or more columns. [input] |
[output] | Quicksort is an efficient sorting algorithm that works by selecting a "pivot" element from the array and partitioning the other elements into two sub-arrays based on whether they are less than or greater than the pivot element. Quicksort then recursively sorts the sub-arrays in the same way. The alg [instruction] | Describe a way to implement quicksort. [input] |
[output] | for i in range(3): for j in range(4): print(i, j) [instruction] | Transform the C code into an equivalent Python program. [input] | int main() { int i, j; for (i = 0; i < 3; i++) for (j = 0; j < 4; j++) printf("%d %d\n", i, j); return 0; }
[output] | import time def throttle_messages(limit, window): count = 0 start = time.time() while count < limit: next_message = yield count += 1 end = time.time() if (end - start) > window: count = 0 start = end y [instruction] | Generate a code to throttle a stream of messages that exceeds a set limit of messages within a certain time window. [input] | limit = 100 time_window = 5 seconds
[output] | def find_kth_smallest_number(list, n, k): list.sort() # kth smallest element return list[k-1] [instruction] | Generate a code to find the kth smallest number in an unsorted list given three inputs (list, k and n). [input] | list = [12, 3, 5, 7, 19] k = 3 n = len(list)
[output] | def fibonacci_generator(n): a, b = 0, 1 while a < 2 * n - 1: yield a a, b = b, a + b [instruction] | Create a python generator that prints fibonacci numbers from n to 2*n-1. [input] | n = 10
[output] | def binary_search(arr, x): l = 0 r = len(arr) - 1 while l <= r: mid = l + (r - l) // 2 if arr[mid] == x: return mid elif arr[mid] < x: l = mid + 1 else: r = mid - 1 return -1 [instruction] | Generate a code to implement a binary search in an array with upto 1 million elements. [input] |
[output] | def add(a, b): # Iterate till there is no carry while (b != 0): # Carry now contains common # set bits of x and y carry = a & b # Sum of bits of x and y where at # least one of the bits is not set a = a ^ b [instruction] | Find the sum of two integers without using + or - signs. [input] | a = 7 b = 5
[output] | def maxSubArraySum(arr): maxsum = arr[0] for i in range(len(arr)): newSum = 0 for j in range(1, len(arr)): newSum += arr[j] if(newSum > maxsum): maxsum = newSum return maxsum [instruction] | Given an array of integers, find the maximum possible sum of a subarray within the array. [input] |
[output] | The 'break' keyword is used to break out of a loop prematurely. It causes an immediate exit from the loop, bypassing any remaining code in the loop. It is generally used inside a conditional statement, such as an 'if' statement, as it can be used to stop the loop from executing when a certain condit [instruction] | What does the 'break' keyword do in a loop structure in Python and how is it used? [input] |
[output] | public class Fibonacci { public static int fibonacci(int number){ if(number == 1 || number == 2){ return 1; } return fibonacci(number-1) + fibonacci(number -2); //tail recursion } public static void printFibonacci(int number){ [instruction] | Create a function in Java to generate Fibonacci numbers up to n. [input] |
[output] | def closest_pair(arr, target): min_difference = 999999 min_pair = (-1, -1) # Iterate through all elements for i in range(len(arr)): # Loop through rest of elements for j in range(i + 1, len(arr)): diff = abs(arr[i] + arr[j] - target) [instruction] | Code an algorithm to find the closest pair of elements in a given array with respect to a given target number. [input] | arr = [10, 22, 28, 29, 30, 40], target = 44
[output] | def zero_sum_pair(list): # loop through the list for i in range(len(list)): for j in range(i + 1, len(list)): if list[i] + list[j] == 0: return [list[i], list[j]] return None [instruction] | Create a function in Python that takes a list and returns the first two elements that adds up to 0. [input] | [1, 5, 2, -7, 3]
[output] | SELECT * FROM Products WHERE SupplierId = 'SupplierId' [instruction] | Write a query in SQL to list the products from a given supplier. [input] |
[output] | def my_function(my_list): output = [] for i in range(0, len(my_list), 2): output.append(my_list[i] * 2) return output By looping over the list in steps of two, the function will only have to go through half of the elements, thus optimizing the runtime. [instruction] | How can you optimized the following program's runtime? [input] | def my_function(my_list): output = [] for i in range(len(my_list)): output.append(my_list[i] * 2) return output
[output] | import pandas as pd data = {'Name':['Tom', 'nick', 'krish', 'jack'], 'Age':[20, 21, 19, 18] } df = pd.DataFrame(data) cols = ['Name', 'Age'] # Creating new Dataframe df_new = df[cols] print(df_new) [instruction] | Given a Dataframe, select the two columns as specified and store into a new separate Dataframe. [input] | import pandas as pd data = {'Name':['Tom', 'nick', 'krish', 'jack'], 'Age':[20, 21, 19, 18] } df = pd.DataFrame(data) cols = ['Name', 'Age']
[output] | my_list = [1, 2, 3, 4] for item in my_list: print(item) [instruction] | Create a for loop for the list. [input] | my_list = [1, 2, 3, 4]
[output] | S ┌───┴───┐ NP VP ┌─┴─┐ │ Bob V NP │ │ V N │ ┌─┴─┐ likes apples [instruction] | Construct a syntax tree representing the following sentence. [input] | Bob likes apples.
[output] | my_dict = {'first': 'one', 'second': 'two', 'third': 'three'} for key, value in my_dict.items(): print(key, value) [instruction] | Write a for loop for the following dictionary. [input] | my_dict = {'first': 'one', 'second': 'two', 'third': 'three'}
[output] | combined_list = set(list_one + list_two) print(list(combined_list)) # ['a', 'b', 'c', 'd', 'e'] [instruction] | How can you combine these two lists without duplication? [input] | list_one = ['a', 'b', 'c'] list_two = ['c', 'd', 'e']
[output] | new_array = [] for x in my_array: new_array.append(x * x) print(new_array) # [4, 9, 16, 25] [instruction] | Create a new array containing the square of each element in the given array. [input] | my_array = [2, 3, 4, 5]
[output] | new_object = { 'name': employee['name'], 'salary': employee['salary'], 'age': 0 } [instruction] | Create a new object with the three properties of an employee specified in the given object. [input] | employee = { 'name': 'John', 'salary': 6000 }
[output] | """ Generate a web page that shows the company name, logo, and description """ <html> <head> <title>Global Inc.</title> </head> <body> <h1>Global Inc.</h1> <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/7/76/Global_Inc_logo.svg/220px-Global_Inc_logo.svg.png"> < [instruction] | Generate a web page that shows the company name, logo, and description. [input] | Company Name: Global Inc. Company Logo: https://upload.wikimedia.org/wikipedia/commons/thumb/7/76/Global_Inc_logo.svg/220px-Global_Inc_logo.svg.png Company Description: Global Inc. is a leading technology provider of innovative solutions for customers around the globe.
[output] | print("challenge. coding a is This") [instruction] | Print the following sentence in reverse order. [input] | "This is a coding challenge."
[output] | """ Write a code that prints each word in a given string on a separate line """ def print_words(string): words = string.split() for word in words: print(word) if __name__ == '__main__': string = "This is a coding challenge" print_words(string) [instruction] | Write a code that prints each word in a given string on a separate line. [input] |
[output] | """ Complete the following code to delete the item at a given index from a list """ index = 4 list_items = [2, 3, 4, 5, 6, 7, 8] # remove the item at index 4 del list_items[index] # print the list print(list_items) [instruction] | Complete the following code to delete the item at a given index from a list. [input] | index = 4 list_items = [2, 3, 4, 5, 6, 7, 8]
[output] | """ Create an HTML page with an input box and a button. When the user clicks the button, it should print out a constant text """ <html> <head> <title>Input Box</title> </head> <body> <input type="text" id="input"></input> <button onclick="printText()">Click Here</button> <scri [instruction] | Create an HTML page with an input box and a button. When the user clicks the button, it should print out a constant text. [input] |
[output] | """ Print only the odd numbers from the given list """ list_items = [2, 3, 4, 5, 6, 7, 8] for item in list_items: if item % 2 != 0: print(item) [instruction] | Print only the odd numbers from the given list. [input] | list_items = [2, 3, 4, 5, 6, 7, 8]
[output] | Complex data type. [instruction] | Classify the following object as having either a simple, complex or a composite data type. [input] | Dictionary
[output] | """ Create a for loop to iterate through a given list and print the list elements """ list_items = [2, 3, 4, 5, 6, 7, 8] for item in list_items: print(item) [instruction] | Create a for loop to iterate through a given list and print the list elements. [input] | list_items = [2, 3, 4, 5, 6, 7, 8]