[output] | def true_false_sum(x): true_sum = 0 false_sum = 0 for i in range(x): if x[i] == booleanTrue: true_sum += 1 else: false_sum += 1 return true_sum, false_sum [instruction] | Help complete the implementation of the following function [input] | def true_false_sum(x): true_sum = 0 false_sum = 0 for i in range(x): if x[i] == booleanTrue: * return true_sum, false_sum
[output] | def find_highest_freq_char(string): counts = {} max_freq_char = "" max_freq = 0 for ch in string: counts[ch] = counts.get(ch, 0) + 1 if counts[ch] > max_freq: max_freq = counts[ch] max_freq_char = ch return max_freq_char [instruction] | How would you write a function to find the highest frequency character in a string? [input] | string = "Hello world!"
[output] | def find_all_valid_ip_addresses(string): valid_ips = [] for i in range(1,4): for j in range(1,4): for k in range(1,4): if i+j+k == len(string): ip_string = string[:i]+"."+string[i:i+j]+"."+string[i+j:i+j+k]+"."+string[i+j+k:] [instruction] | Create a method to find all valid IP addresses that can be formed using a given string. [input] | string = "25525511135"
[output] | For loops are better than while loops in Python because they provide a clearer syntax and are easier to debug due to their predictable and structured behavior. For loops are also more efficient than while loops since they don't require explicit initialization and condition checking, while while loop [instruction] | Explain why using "For" loops can be a better choice than using "While" loops in Python. [input] |
[output] | textarea { color: #ff0000; } [instruction] | Edit the given CSS code to achieve the desired effect. [input] | CSS code to change the colour of font in a text box to red: textarea { color: #000; }
[output] | struct TreeNode { struct TreeNode* left; struct TreeNode* right; int data; }; TreeNode* LCA(TreeNode* root,TreeNode* node1, TreeNode* node2) { int small = min(node1->data, node2->data); int large = max(node1->data, node2->data); if (root == NULL) return NUL [instruction] | Given a Binary search tree, write a C++ program to find the lowest common ancestor (LCA) of two given nodes in the BST. [input] | Tree: 8 / \ 3 10 / \ / 1 6 14
[output] | S -> bAa A -> AaA | aAa | bAb | abB | ε [instruction] | Provide a context-free grammar to generate strings that contain only a’s and b’s and which have the same number of a’s as b’s. [input] |
[output] | SELECT name, date_of_birth FROM Employees WHERE date_of_birth > '1980-01-01' [instruction] | Write a SQL query to show the name and date of birth of all employees born after 1st January 1980. [input] |
[output] | function doSomething() { return new Promise((resolve, reject) => { // do something resolve("Done!"); }); } function main() { doSomething() .then((result) => { console.log(result); }) .catch((err) => { console.log(err); }); } main(); [instruction] | Rewrite the given code to use JavaScript Promises instead of callbacks. [input] | function doSomething(callback) { // do something callback("Done!"); } function main() { doSomething(function(result) { console.log(result); }); } main();
[output] | Quicksort is an efficient comparison-based sorting algorithm that works by taking a pivot element and partitioning the list/array into two parts: elements smaller than the pivot element and elements larger than the pivot element. The quicksort algorithm then sorts both sublists recursively until the [instruction] | Explain how a quicksort algorithm works. [input] |
[output] | class FreqCollection(object): def __init__(self): self.words = {} def add_word(self, word): if word in self.words: self.words[word] += 1 else: self.words[word] = 1 def get_word_freq(self, word): if word in self.words: [instruction] | Create a class in python to store a collection of words and their frequency count. [input] |
[output] | arr = [7, 5, 8, 4, 9, 6, 1, 3, 2] # Create a list of the top 3 highest valued elements top_three = [max(arr)] # start with the maximum elements arr.remove(max(arr)) # remove the maximum element from the list top_three.append(max(arr)) #Add the second maximum element to top_three arr.remove(max(arr) [instruction] | Create a list of the top 3 highest valued elements in the following array. [input] | arr = [7, 5, 8, 4, 9, 6, 1, 3, 2]
[output] | # Format the output of a number to contain comma-separated thousands def format_number(num): return '{:,}'.format(num) # Get the formatted output print(format_number(323456789)) # Output: 323,456,789 [instruction] | Format the output of a number to contain comma-separated thousands. [input] | num = 323456789
[output] | Final_list = [i+j for i in range(10) for j in range(10)] [instruction] | Recreate this nested for loop in a single line of code. [input] | Final_list = [] for i in range(10): for j in range(10): Final_list.append(i+j)
[output] | # Write an expression to check if a given number is a perfect square import math def is_perfect_square(num): return math.sqrt(num).is_integer() # Check the given number print(is_perfect_square(16)) # Output: True [instruction] | Write an expression to check if a given number is a perfect square [input] | num = 16
[output] | Different types of sorting algorithms include Bubble Sort, Insertion Sort, Selection Sort, Heap Sort, Merge Sort, Quick Sort, Radix Sort, Shell Sort, Counting Sort, and Bucket Sort. [instruction] | List all the different types of sorting algorithms. [input] |
[output] | items = ["apple", "orange", "banana"] quantity = [4, 2, 7] cost = [2.00, 1.50, 3.00] [instruction] | Parse the following JSON structure and store each element into a variable. [input] | { "items": ["apple", "orange", "banana"], "quantity": [4, 2, 7], "cost": [2.00, 1.50, 3.00] }
[output] | SELECT fruit_name FROM fruits_table; [instruction] | Generate a SQL query that selects all the fruit names from a table. [input] |
[output] | function reverseSort(array){ return array.sort(function(a, b){ return b - a; }); } reverseSort([9,2,8,4,7]); // Output: [9,8,7,4,2] [instruction] | Create a JavaScript function that reverse alphabetically sort an array of numbers. [input] | [9, 2, 8, 4, 7]
[output] | Minimum: 1 Maximum: 12 Average: 6.14 [instruction] | Calculate the minimum, maximum and average of the following array. [input] | [2, 3, 1, 5, 9, 12, 8]
[output] | <a href="https://example.com" target="_blank">Click here</a> [instruction] | Make the following HTML code valid by adding the missing attributes. [input] | <a href="https://example.com" target>Click here</a>
[output] | display alert "hello world" [instruction] | Create an Applescript that displays an alert message saying 'hello world'. [input] |
[output] | for i in range(1,11): print(i) [instruction] | How would you create a for-loop in Python to iterate through all the integers from 1 to 10? [input] |
[output] | nums = [1, 2, 3, 4] [instruction] | Make the following sentence compliant with PEP 8. [input] | nums=[1,2,3,4]
[output] | let sum = 0; for(i = 0; i < arr.length; i++){ sum += arr[i]; } console.log(sum); // Output: 23 [instruction] | Calculate the sum of the following numbers using JavaScript. [input] | [1, 4, 8, 10]
[output] | The greatest common factor of 18 and 12 is 6. [instruction] | Calculate the greatest common factor of 18 and 12. [input] |
[output] | SELECT name FROM countries; [instruction] | Suggest a SQL query to select all countries from the table. [input] | Table name: countries Columns: - name (text) - population (integer) - area (float) - capital_city (text)
[output] | SELECT SUM(area) FROM countries; [instruction] | Find the total area of all countries from the table. [input] | Table name: countries Columns: - name (text) - population (integer) - area (float) - capital_city (text)
[output] | class Node: def __init__(self, value): self.value = value self.left = None self.center = None self.right = None [instruction] | Generate a ternary tree data structure in Python. [input] |
[output] | def is_anagram(str1, str2): char_map1 = {} char_map2 = {} for char in str1: if char in char_map1: char_map1[char] += 1 else: char_map1[char] = 1 for char in str2: if char in char_map2: char_map2[char] += 1 else [instruction] | Construct an algorithm to check if two strings have the same characters and same frequency of characters. [input] | String A: hello String B: ollhe