instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Create a function in Python that takes in an integer N as a parameter. The function should generate N multidimensional arrays, where each array represents a 4x4 matrix. Each element of the matrix should be a randomly generated integer between -100 and 100.
Additionally, the function should calculate and return the sum... | codefeedback |
Create a MongoDB query to get the average salary for all employees who have been with the company for at least 5 years, have a job title of "Senior Software Engineer", and have a performance rating of at least 4. | codefeedback |
Convert the given Python code into a single line list comprehension statement that creates a list of all even numbers between 1 and 100, excluding numbers that are multiples of 3. The resulting list should be sorted in descending order. | codefeedback |
Create a function that takes a list of integers and returns a tuple containing the second highest and second lowest values of the list. However, if the list is empty or contains less than two elements, the function should return None. If the list contains only two elements, the function should return a tuple with those... | codefeedback |
Find the largest prime key in a dictionary that contains both prime and composite integers, and return the sum of its corresponding value and the lengths of all the other values. You are not allowed to use built-in functions for sorting or finding the maximum value, and you must implement a function to determine whethe... | codefeedback |
In the following JavaScript function, edit the function body so that it returns the number stored in the variable 'currentNum' divided by 5 and then subtracted by 3. The function should also check if the 'currentNum' is a positive integer and throw an error if it is not. | codefeedback |
Write a JavaScript code snippet to sort an array of objects by a given property name in descending order. Additionally, if two objects have the same property value, sort them by another property called "weight" in ascending order. If "weight" is also the same for two objects, sort them by the "name" property in alphabe... | codefeedback |
Write a JavaScript code to print the characters of a string one by one in a custom function called "printCharacter". The function should take in a string and display each character individually. However, instead of using loops or recursion, you must implement the function using a single line of code using functional pr... | codefeedback |
Parse this HTML code and extract the text that is enclosed within the first set of paragraph tags, ignoring any nested tags or special characters such as line breaks and tab spaces.
Additional Requirements:
- Your solution should handle cases where there are multiple sets of paragraph tags in the HTML code.
- The extr... | codefeedback |
Create a function in Java to remove values from an array that are greater than a given number, but only if the sum of their digits is a prime number and the value itself is a palindrome. | codefeedback |
Create a Java program for finding the first non-repeated character in a string, while ignoring any whitespace characters. The string may contain special characters and numbers.
String: hello 123&@^# world | codefeedback |
Create a JSON object for a list of 1000 people. Each person should have the following attributes:
- Name: A random string of length between 5 and 10 characters.
- Age: A random integer between 18 and 65.
- Gender: A random string representing either "Male" or "Female".
- Address: A random string of length between 10 an... | codefeedback |
Create a C++ program for computing the sum of the digits in a number, where the number can have up to 10^9 digits. Your program should handle both positive and negative numbers. Additionally, you are required to implement the program using a recursive function. | codefeedback |
Identify the wrong statement about the recursive function in the given code. The function should also return the number of times the recursive function was called. The code should be implemented using dynamic programming and the time complexity should be O(n). | codefeedback |
Generate a regular expression that matches strings containing any number of digits, but does not contain any non-digit character. Additionally, the regular expression should not match any string that ends with a digit. Provide an example of a string that matches the regular expression and another example of a string th... | codefeedback |
Identify the class, the subnet mask, and the default gateway of the given IP address.
IP Address: 192.168.1.1
Additional Requirements:
1. Implement the solution without using any built-in libraries or functions for IP address manipulation.
2. The solution should handle IPv6 addresses as well, in addition to IPv4 addre... | codefeedback |
Write a program that determines if two strings are anagrams of each other. An anagram is a word or phrase formed by rearranging the letters of another word or phrase.
#Test Inputs#
String 1: dormitory
String 2: dirty room
#Test Outputs#
True
#Additional Information#
- The strings may contain spaces and punctuation ... | codefeedback |
Trace the output of the given program and explain the time and space complexity of the code.
def foo(x, y):
if y > 0:
for i in range(y):
x += i
return x
else:
for i in range(-y):
x *= i
return x
a = foo(2, 3)
b = foo(2, -2)
print(a, b)
Time Complexity:... | codefeedback |
Write an angular directive to highlight the selected word in a text, but only if it is preceded by a certain pattern of letters and followed by a certain pattern of letters. Additionally, the directive should also check for nested patterns within the selected word and only highlight the outermost occurrence. | codefeedback |
Edit the SQL query to get the users from Canada who joined within the last 3 months and have made at least 10 purchases. Additionally, the purchases must be of different products, i.e., no two purchases should have the same product_id.
SELECT users.id, users.name
FROM users
INNER JOIN purchases ON users.id = purchase... | codefeedback |
Find the sum of all prime numbers between 1 and 100000.
#Erroneous Code#
```python
def is_prime(n):
if n == 2:
return True
elif n % 2 == 0:
return False
else:
for i in range(3, int(n**0.5) + 1, 2):
if n % i == 0:
return True
return False
sum = 0
... | codefeedback |
Write an SQL query to return the top three highest-scoring players from a table 'scores' who have played at least 10 games. Also, include the average score, highest score, and lowest score for each player in the result. | codefeedback |
Write an HTML program to create a complex page layout with multiple columns, responsive design, a sticky navigation bar, and implement a custom scrollbar for a specific section of the page. | codefeedback |
Write a Java program to calculate the exponential value of a number using only basic arithmetic operations (addition, subtraction, multiplication, and division) and loops. Do not use any built-in libraries or functions for exponentiation. Additionally, the program should handle negative exponents and inputs with decima... | codefeedback |
Generate a unique ID string in Java that adheres to the following requirements: the string must contain at least 10 characters, it must start with a capital letter, it must include at least one special character, it must not contain any repeating characters, and it must not contain any vowels. | codefeedback |
Look at the given code and find the bug in it.
Write a function `add_numbers` that takes in two integers `x` and `y` as parameters and returns their sum. However, there is a bug in the code that needs to be fixed.
The bug in the code is that it adds an extra value of 1 to the sum. Remove the `+ 1` from the return sta... | codefeedback |
Write a JavaScript function to convert the given string to title case, but excluding certain words from being capitalized. The excluded words are: "the", "and", "or", "but". The function should also handle hyphenated words properly. | codefeedback |
Read the given CSS selector and explain what it does. Additionally, provide an example of HTML code where this selector would not work as expected.
Furthermore, write a function in your preferred programming language that takes in a CSS selector as input and returns a boolean value indicating whether or not the select... | codefeedback |
Extract the digits from a given string and return them as a list, without using any built-in functions or regular expressions. The input string may contain both letters and digits, and may have leading or trailing whitespace. The output list should contain the digits in the same order as they appear in the string. Addi... | codefeedback |
How can you access the value of a key from a JavaScript object, using only one line of code and without using any built-in JavaScript methods or functions? Provide a piece of erroneous code as a reference to increase misdirection.
#Updated Test#
Consider the following JavaScript object:
```javascript
const obj = {a: 1... | codefeedback |
Design and implement an algorithm to find the shortest path between two nodes in a weighted directed graph. The algorithm should have a maximum time complexity of O(n log n) and should work efficiently for large graphs with up to 10^6 nodes.
The algorithm should consider the weight of the edges and find the path with ... | codefeedback |
Write a SQL query to retrieve all unique customers who have made more than 10 purchases in the past month, ordered by the total amount spent. Additionally, exclude any customers who have made purchases in the last week. | codefeedback |
Write a React component to display a list of all the countries, sorting them alphabetically. Additionally, the component should allow users to filter the countries based on their population size and GDP per capita. Users should be able to select a range for the population size (e.g., display countries with populations ... | codefeedback |
Solve the following problem. Given an array of positive integers, return an array with the elements multiplied by three and sorted in descending order. Additionally, the returned array should only contain numbers that are divisible by 2. arr = [4, 12, 8, 6] | codefeedback |
Write a C program to find the sum of the first and last elements in an array and print the result. The array should contain at least 100,000 elements and the sum should be stored in a separate variable. Additionally, the program should ensure that the sum is always positive and handle any overflow that may occur. | codefeedback |
Write a JavaScript code to filter a given array and return only the even numbers. However, the code should also handle negative numbers and floating-point numbers. Implement the solution using a recursive function and ensure that the time complexity of the solution is not more than O(n), where n is the length of the in... | codefeedback |
Write a SQL query to get the names, total number of orders, average order amount, and the most recent order date for each customer in a table called 'orders'. | codefeedback |
Write a Python code to sort a given list of integers into descending order, without using any built-in sorting functions or methods, and without using any additional data structures. | codefeedback |
Write a C program to find the difference between the maximum and minimum values in an array, without using any loops or recursion. You are only allowed to use the following functions: malloc(), free(), printf(), and scanf(). Additionally, you must ensure that the program handles empty arrays correctly and returns an ap... | codefeedback |
Create a GraphQL query that returns the top five countries with the highest population, but exclude any countries with a population greater than 50 million and less than 200 million. Additionally, the query should include the country's GDP, area, and official language. | codefeedback |
Rewrite the code to validate a credit card number using JavaScript, while also considering potential errors in the code and adding error handling mechanisms. Additionally, provide a piece of erroneous code that attempts to validate the credit card number but contains a logical error. | codefeedback |
Calculate the value of PI using the Leibniz formula, but ensure that the calculation is accurate up to at least 100 decimal places. Additionally, your solution should be able to handle large input values for the number of iterations, up to 10^9, without causing a memory overflow or taking an unreasonable amount of time... | codefeedback |
Using React, create a component to display a table containing a list of cities. The table should have the following columns: City Name, Population, Average Temperature, Number of Tourist Attractions, and Percentage of Annual Rainfall. The table should be sortable by each column in both ascending and descending order. A... | codefeedback |
What is the syntax for performing an instruction inside a loop in JavaScript? Provide a piece of erroneous code as a reference to increase misdirection. Also, explain the purpose of the 'break' statement in JavaScript loops and provide an example of its usage. | codefeedback |
Write a recursive function in Python to calculate the factorial of a given positive integer. The function should take the integer as an input parameter and return its factorial.
Additionally, the function should include error handling to handle cases where a non-positive integer is provided as an input. In such cases,... | codefeedback |
Given a list of integers, determine the sum of all even elements in the list that are divisible by 3. If the list is empty or contains only odd elements, return -1. | codefeedback |
Create a Python script that inputs a positive integer and prints the sum of all prime numbers smaller than or equal to the input number.
Requirements:
- The script should be able to handle input numbers up to 10^6.
- The time complexity of the solution should be less than O(n^2).
- You should avoid using any external ... | codefeedback |
What is the purpose of the TensorFlow library and how does it differ from other deep learning frameworks? Provide examples of commonly used programming languages that support TensorFlow. | codefeedback |
Re-implement the quick_sort algorithm using an iterative approach instead of a recursive approach. Additionally, optimize the algorithm to have a time complexity of O(nlogn) and a space complexity of O(logn). | codefeedback |
Write a function in C++ that takes in a string of text and removes all the punctuation from the string. Additionally, the function should also remove any numbers from the string. The function should return the modified string.
Your solution should have a time complexity of O(n), where n is the length of the input stri... | codefeedback |
Read a given code and determine if it contains any errors or not.
Write a function called `factorial` that takes an integer `n` as input and returns the factorial of `n`. The factorial of a non-negative integer `n`, denoted by `n!`, is the product of all positive integers less than or equal to `n`.
The function should... | codefeedback |
You are given a list of integers and need to calculate the maximum number in the list. However, you are not allowed to use any built-in functions or methods to find the maximum value. You need to implement your own algorithm to solve this problem.
Additionally, you need to handle the case where the list is empty and r... | codefeedback |
Create a function in JavaScript that calculates the factorial of a given number, but with the restriction that you cannot use loops or the multiplication operator.
Example:
Input: 5
Output: 120
Note:
You are not allowed to use loops, recursion, or the multiplication operator to calculate the factorial. | codefeedback |
Read a code that prints out the Fibonacci Series up to a given number. The code should also calculate and print the sum of all the even numbers in the Fibonacci Series. Additionally, the code should be optimized to have a time complexity of O(n) and a space complexity of O(1). | codefeedback |
Create a function in Python that finds the sum of all prime numbers between two given numbers. Additionally, the function should implement error handling to handle cases where the given numbers are negative or the second number is smaller than the first number. | codefeedback |
Edit the following Java code to create a method which will calculate the area of a rectangle, given its width and length. However, you are not allowed to use the multiplication operator or the Math library functions. Additionally, the time complexity of the solution should be O(1) and the space complexity should be O(1... | codefeedback |
Create a program that will guess a number between 0 and 1000, with the additional constraint that the number must be a multiple of 5.
Explanation: By increasing the range of numbers to 0 to 1000 and adding the constraint that the number must be a multiple of 5, it adds an additional level of complexity to the problem.... | codefeedback |
Create a code that recognizes if an inputted string is a palindrome or not. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward. The code should handle cases with spaces and punctuation marks as well.
In addition to the original requirements, the code should... | codefeedback |
Create a Python class for a movie instance with the following fields: name (string), director (string), year (integer), and rating (float). Implement the following methods:
1. `get_name()`: Returns the name of the movie.
2. `get_director()`: Returns the name of the director of the movie.
3. `get_year()`: Returns the y... | codefeedback |
Create a NodeJS server that listens on port 8080 and serves a simple HTML page. However, the HTML page should be dynamically generated based on user input.
When a GET request is made to the server, it should prompt the user to enter their name. The server should then take the user's name and generate an HTML page that... | codefeedback |
Create a function in JavaScript that calculates the area of a rectangular room given its width and length. The function should also handle irregular-shaped rooms by accepting an optional parameter for the number of sides in the room, and an array of lengths for each side. Additionally, the function should validate the ... | codefeedback |
Write a code to find the number of days between two given dates, considering leap years, using the calendar module.
First date: 12th March 2021
Second date: 18th September 2025 | codefeedback |
Write a Java program that counts the number of vowels in a given string and also keeps track of the positions of the vowels in the string. The program should then print the number of vowels found, the positions of each vowel, and the total number of non-vowel characters in the string. The string can contain upper and l... | codefeedback |
Explain the practical application and limitations of sorting algorithms in the context of large-scale data processing and real-time systems. Additionally, provide a code snippet of an incorrect implementation of a sorting algorithm and explain the specific errors and their impact on the algorithm's performance and func... | codefeedback |
Explain the concept of supervised learning and unsupervised learning, and provide a detailed example of each. Additionally, discuss the advantages and limitations of each approach in terms of accuracy, interpretability, and scalability. In your discussion, consider how different factors such as dataset size, feature co... | codefeedback |
Rewrite the following jQuery code to its vanilla JavaScript equivalent, without using any built-in DOM manipulation methods.
- The code should still iterate over each `li` element inside the `#list` element.
- Inside the iteration, you should retrieve the text content of each `li` element, convert it to uppercase, and ... | codefeedback |
Write a HTML code snippet to create a 8x8 table with a border, each cell having a different background color, and a gradient effect on the table. Additionally, include a hover effect on each cell where the background color changes when the mouse is over a cell. | codefeedback |
Write a function in JavaScript that checks if a given string is a valid HTML color code. A valid color code should start with a "#" symbol and be followed by exactly six characters, where each character can be either a digit (0-9) or a letter (A-F, case-insensitive). Additionally, the function should also check if the ... | codefeedback |
Using a while loop, find and print all prime numbers between 0 and a given number, n, where n can be up to 1 million. The solution should have a time complexity of O(sqrt(n)) and a space complexity of O(1). | codefeedback |
Write a lambda expression to deduct 10 from a number, but only if the number is greater than 100, is divisible by 5, and is not a prime number. | codefeedback |
Write a JavaScript code to count the number of occurrences of an input string in a text string.
str1 = "My name is Mary and my friend's name is Sarah"
str2 = "name"
Expected output: 2
Explanation:
1. Initialize a counter variable, count, to 0.
2. Split the text string, str1, into an array of words using the split()... | codefeedback |
Sort a given dictionary of strings in reverse alphabetical order. | codefeedback |
Remove the first even number in a list of at least 5 elements using slicing. The list must not contain any duplicate elements and the element to be removed must be divisible by both 3 and 5. The final list must be sorted in descending order. [10, 8, 6, 4, 2] | codefeedback |
Generate a function `recursive_product` that computes the product of a list of integers recursively. The function should not use any built-in functions or operators for multiplication (such as `prod()` or `*`). Instead, it should use a recursive approach to multiply the elements in the list.
Additionally, the function... | codefeedback |
Using list comprehension, create a list of all prime numbers from 0 to 1000, and then sort the list in ascending order. | codefeedback |
Write a program that takes a list of integers as input and returns a new list containing only the prime numbers from the original list. Additionally, the program should also remove any duplicates from the original list before checking for prime numbers. | codefeedback |
Write an SQL query to delete all the records in a table named "users" where the age is greater than 30 and the registration date is before January 1, 2020, and the user has made at least 3 purchases with a total value of over $100. | codefeedback |
Write a for loop to print out the squared value of each element in the list. However, you should only square the odd numbers in the list. If the element is not an odd number, print out "Skipped" instead. Additionally, the program should keep track of the sum of all the squared odd numbers and print it out at the end. | codefeedback |
Change the following code to accept multiple arguments and handle different data types. Additionally, modify the code to handle additional data types such as strings and arrays.
```javascript
// Original code
function add(a, b) {
return a + b;
}
// Updated code
function add(...args) {
let sum = 0;
for (let i = ... | codefeedback |
Sort an array of positive integers in ascending order without using any built-in sorting methods or functions. The array should contain at least 10 elements and each element should be between 1 and 100 (inclusive). | codefeedback |
Create a class Person with the following attributes:
- name: a string representing the person's full name
- age: an integer representing the person's age
- gender: a string representing the person's gender (male, female, or other)
The Person class should have the following methods:
1. `get_name()`: a method that retur... | codefeedback |
Output the binary representation of a given number, ensuring that the solution does not use any built-in functions or libraries to convert the number to binary. Use only bitwise operations and do not exceed a time complexity of O(log n).
14 | codefeedback |
Calculate the mean of the following list of numbers: 4, 6, 8, 10, 12. Your solution should not use any built-in functions or libraries for calculating the mean. Additionally, ensure that your solution is efficient and does not have a time complexity higher than O(n). | codefeedback |
Write a function that prints Fibonacci numbers up to N (N>1) without using recursion and using constant space complexity.
In addition, optimize the function to have a time complexity of O(N) and avoid redundant calculations by using memoization. | codefeedback |
Convert the given date and time into the ISO 8601 date format, taking into account time zones, daylight saving time adjustments, and leap years. Additionally, the solution should handle any input format for the date and time (e.g. different date separators, different time formats). | codefeedback |
Given a list of numbers, write a function in Java to arrange the list in ascending order. However, you are not allowed to use any built-in sorting methods or libraries.
nums = [10, 2, 9, 6]
Increase the difficulty by requiring the function to have a time complexity of O(nlogn) or better, and also to be space efficien... | codefeedback |
Write a Python function to sort the given array of dictionaries by key value in descending order. The dictionaries in the array will have the following keys: 'name' (string), 'age' (integer), and 'salary' (float). The function should prioritize sorting based on 'name' first, then 'age', and finally 'salary'.
arr = [{'... | codefeedback |
Write a function that takes a string and returns a new string with each word capitalized and reversed.
var string = 'hello world';
Example:
capitalizeAndReverseWords(string) => 'Olleh Dlrow'
Note:
- The input string will only contain alphabetical characters and spaces.
- The words in the string are separated by a si... | codefeedback |
Create an array of 1000 students and output their names in descending order based on their average grade. Each student object will now have an additional property called "grades", which is an array of 5 grades (ranging from 0 to 100). The average grade should be calculated as the sum of all grades divided by 5.
var st... | codefeedback |
Provide a solution for displaying another message if the user's input is not a valid name. The input is considered valid if it consists of only alphabetic characters (upper or lower case) and spaces. Additionally, the name should not contain any special characters or numbers. | codefeedback |
Given a string of lowercase alphabets, compress the string using the RLE (Run-Length Encoding) algorithm and achieve a time complexity of O(n), where n is the length of the input string.
Example 1:
Input: "aaabbbccc"
Output: "a3b3c3"
Explanation: The input string contains three consecutive a's, three consecutive b's, ... | codefeedback |
Write a script that sorts an array of numbers from smallest to largest. The script should use a custom sorting algorithm instead of built-in sorting functions. Additionally, the script should only use a constant amount of extra memory (i.e., no additional arrays or data structures are allowed). Finally, the script shou... | codefeedback |
Create a class called "Person" with the following properties: a name (string), an id (integer), a date of birth (string), and a gender (string). The date of birth should be in the format "YYYY-MM-DD" and must be validated to ensure it is a valid date. The gender should be either "Male" or "Female". Additionally, the id... | codefeedback |
Create a program that outputs the results of an election. Each candidate's name must be a string consisting of only uppercase letters, with a maximum length of 10 characters. The number of votes for each candidate must be a positive integer not exceeding 1000. The total number of votes must be at least 100. The program... | codefeedback |
Suggest a possible numpy code to normalize a data in the following manner.
Normalize the data such that the values lie in the range -1 to 1. Additionally, ensure that any values below -0.3 are rounded down to -1 and any values above 0.3 are rounded up to 1. The time complexity of the solution should be O(n), where n is... | codefeedback |
Construct a code to add a new item to the end of the list only if it meets the condition that the item is a fruit, its name starts with a consonant, and it contains at least 3 different vowels in its name.
list_of_items = ["apple", "orange", "cherry"] | codefeedback |
Implement a self-balancing binary search tree (AVL tree) that supports the following operations:
1. Insertion: Given a key, insert it into the AVL tree while maintaining balance.
2. Deletion: Given a key, delete it from the AVL tree while maintaining balance.
3. Search: Given a key, search for it in the AVL tree and r... | codefeedback |
Suggest a python code to print all the even numbers from the given list in ascending order, while also ensuring that the code has a time complexity of O(n) and does not use any built-in Python functions. Additionally, the code should only use a single loop and should not use any additional data structures or variables ... | codefeedback |
Suggest a code to print the last two elements of a list in reverse order, convert them to uppercase, and then calculate the sum of their lengths.
list_of_items = ["apple", "banana", "cherry", "orange"] | codefeedback |
Suggest a code to iterate a list of numbers and add them to a variable. However, you are not allowed to use any built-in functions or operators for addition. You can only use basic arithmetic operations such as subtraction, multiplication, and division. The list_of_numbers can contain both positive and negative integer... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.