[output] | int result = a.compareTo(b); //Result: 1 (because "hello world" is greater than "goodbye world") [instruction] | Compare the two strings, and return 0 if they are the same, 1 if a is greater than b, or -1 if b is greater than a. [input] | Strings: a = "hello world" b = "goodbye world"
[output] | public static int[] mergeArrays(int[] arr1, int[] arr2) { int[] result = new int[arr1.length + arr2.length]; int i = 0, j = 0, k = 0; while (i < arr1.length && j < arr2.length) { if (arr1[i] < arr2[j]) result[k++] = arr1[i++]; else res [instruction] | Design a method which takes in two sorted array of size n and m, and returns a new sorted array of size n + m [input] | int arr1[] = {1, 3, 5, 7}; int arr2[] = {2, 4, 6, 8};
[output] | function checkChar(str, char) { if (str.indexOf(char) > -1) { return true; } else { return false; } } if (checkChar('Hello World!', 'l')) { console.log('Character is present in the string'); } else { console.log('Character is not present in the string'); } [instruction] | Write a JavaScript program to check whether a particular character is present in a given string or not [input] | String: 'Hello World!' Character: 'l'
[output] | SELECT DISTINCT customer_name FROM orders; [instruction] | Create a SQL query to output the names of all the customers in the orders table [input] |
[output] | public class SumOfElements { // Function to get sum of all elements. public static int getSum(int[] arr) { int sum = 0; for (int i : arr) sum += i; return sum; } public static void main(String[] args) { int arr[] = { 4 [instruction] | Design a program to find the sum of all numbers in an array of size 5 [input] | int arr[] = {4, 8, 2, 6, 1};
[output] | arr = [[[0 for x in range(3)] for y in range(3)] for z in range(3)] for x in range(3): for y in range(3): for z in range(3): arr[x][y][z] = int(input()) [instruction] | Edit an existing Python script to read a 3D array of size 3 x 3 x 3 [input] |
[output] | SELECT customer_name, COUNT(*) FROM orders GROUP BY customer_name; [instruction] | Write a SQL query to print the name and total orders of each customer [input] |
[output] | def reverse_name(name): return name[::-1] [instruction] | Write a function that takes a name as a parameter and returns its reverse counterpart. [input] | name = "John"
[output] | def same_letter_words(word_list): same_letter_words = [word for word in word_list if len(set(word)) == 1] return same_letter_words [instruction] | Write a function to take a list of strings and return only the words made up of the same letter. [input] | word_list = ["aaa", "cab", "bba"]
[output] | def sort_ascending(numbers): numbers.sort() return numbers [instruction] | Using the list of numbers, create a function to sort the list into ascending order. [input] | numbers = [6, 4, 3, 2, 8]
[output] | def mean_value(data): sum = 0 count = 0 for value in data.values(): sum += value count += 1 return round(sum/count, 2) [instruction] | Using the data provided, create a function to calculate the mean value of the elements inside the dictionary. [input] | data = {"John": 8.5, "Jane": 9, "Bob": 5}
[output] | def triangle_pattern(height): star = "*" for i in range(height): print(star*(i+1)) [instruction] | Write a function to print out the triangle pattern as shown in the example. [input] | height = 3
[output] | function reverseString(str) {...} or function reverseWord(str) {...} [instruction] | Suggest a function name for a function that reverses a string. [input] |
[output] | // Generate a random 3-digit number let num = Math.floor(Math.random() * (999 - 100 + 1) + 100); [instruction] | Generate a random 3-digit number without using any in-built methods [input] |
[output] | class Student: def __init__(self, first_name, last_name, age, grade): self.first_name = first_name self.last_name = last_name self.age = age self.grade = grade [instruction] | Create a class in Python for a student which should include the following fields: first name, last name, age, and grade. [input] |
[output] | ^[6-9][0-9]{9}$ [instruction] | Write a regular expression to validate an Indian mobile number. [input] |
[output] | Quick Sort [instruction] | Suggest a sorting algorithm which takes minimal time to execute. [input] |
[output] | You can pass multiple parameters in a function by using either argument lists, or by using objects or arrays to group multiple parameters together. [instruction] | How can you pass multiple parameters in a function? [input] |
[output] | if (condition) { // statements when condition is true } else { // statements when condition is false } [instruction] | Provide a syntax for an if-else statement in Javascript. [input] |
[output] | MatrixDataStructure [instruction] | Suggest a class name for a class which models a data structure for storing a 2-dimensional array. [input] |
[output] | void getLongestString(string str1, string str2) { // variables to store length of both strings int l1 = str1.length(), l2 = str2.length(); if (l1 > l2) cout << str1; else cout << str2; } [instruction] | Write a C++ function which allows the user to input two strings and prints the longest string. [input] |
[output] | """ Pandas is a Python library used for data analysis and manipulation. It is used for data wrangling, data preparation, and data exploration. Pandas allows for easy manipulation and analysis of data, as well as performing high-level operations on it. It also supports several data formats including [instruction] | What is pandas and why would someone use it? [input] |
[output] | """ A code to perform a depth-first search on a binary search tree """ # Node class class Node: # Constructor to create a new node def __init__(self, key): self.key = key self.left = None self.right = None # A function to do inorder tree traversal def de [instruction] | Write a code to perform a depth-first search on a binary search tree. [input] |
[output] | """ The best way to reverse the characters in a string is by using the slicing option of a string object. The string slicing reverses a string by slicing it from the end of the string and going to the beginning of the string. This can be done with the following syntax: string_name[::-1] For exam [instruction] | Given a string, what is the best way to reverse the characters in it? [input] | <noinput>>
[output] | """ The steps to debug a code are: 1. Identify the errors in the code. 2. Identify the source of the errors. 3. Examine the context of the errors. 4. Determine possible solutions. 5. Test each solution and check the results. 6. Refine the solution by repeating steps 4 and 5 until the issue is [instruction] | What are the steps to debug a code? [input] |
[output] | """ A Python code for a basic for loop """ for i in range(10): print(i) [instruction] | Create a Python code for a basic for loop. [input] |
[output] | """ A code that takes the input of two strings, and returns the longest common substring in them """ def longest_common_substring(s1, s2): m = [[0] * (1 + len(s2)) for i in range(1 + len(s1))] longest, x_longest = 0, 0 for x in range(1, 1 + len(s1)): for y in range(1, 1 + len(s2 [instruction] | Write a code that takes the input of two strings, and returns the longest common substring in them. [input] |
[output] | """ The main difference between Python 2 and Python 3 is in how strings are treated. In Python 2, strings are written in byte strings or fully Unicode strings; in Python 3, strings are written in Unicode by default. Other differences include the import statement, integer division, integer in range f [instruction] | What is the difference between Python 2 and Python 3? [input] |
[output] | """ Some of the most commonly used libraries in data science are NumPy, pandas, Matplotlib, Scikit-Learn, TensorFlow, Theano, Seaborn, Keras, NLTK, Apache Spark, and Bokeh. These libraries are used for a variety of tasks such as data manipulation, machine learning, visualization, natural language pr [instruction] | What libraries are commonly used in data science? [input] |
[output] | """ A code to find the longest common prefix among a given set of strings """ def longest_common_prefix(strs): if not strs: return "" shortest_str = min(strs,key=len) for i, ch in enumerate(shortest_str): for other in strs: if other[i] != ch: [instruction] | Write a code to find the longest common prefix among a given set of strings. [input] |