instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Rewrite the following code in to a recursive function with a limit of 100 recursive calls. The function should also handle negative input values and raise a ValueError if the input is not an integer. Additionally, the function should only be allowed to use a single parameter for input and output, and should not use any... | codefeedback |
Write a JavaScript function to generate all possible combinations of a given set of elements, with the additional requirement that each combination must have a specific length specified as an input parameter to the function. Additionally, each element in the set can only be used once in each combination, and the output... | codefeedback |
Find the Big O notation of the following code, assuming that the input "n" is always a positive integer and the code must be implemented recursively. Additionally, analyze the space complexity of the code.
```python
def fibonacci(n):
if n <= 1:
return n
else:
return fibonacci(n-1) + fibonacci(n... | codefeedback |
Generate code to create a 5 x 5 matrix with values 1 to 25, where each element in the matrix is a prime number. Additionally, implement a function that checks if a given number is prime and use it to validate the matrix. | codefeedback |
Write a SQL query to get a list of all the employees with a salary greater than $50,000, whose age is less than 30, and whose job title is either 'Manager' or 'Senior Developer'. | codefeedback |
Find the bug in the following code and provide a more efficient solution.
# Original Code
def multiply(x, y):
z = 0
while y > 0:
y = y - 1
z = z + x
return z
# Bug Fix
def multiply(x, y):
z = 0
while y > 0:
if y % 2 == 1: # only add x when y is odd
z = z + x
... | codefeedback |
Use the given test data to debug the following code and modify it to handle additional constraints. Write a function named "check_odd_even" that takes an integer "number" as input and returns "even" if the number is even, divisible by 4, and a multiple of 6, "odd" if the number is odd, divisible by 3, and a multiple of... | codefeedback |
Please find the transpose of a matrix in-place. The transpose of a matrix is obtained by swapping its rows with columns.
Example:
Input:
matrix = [[2, 3, 4], [1, 5, 3]]
Output:
[[2, 1], [3, 5], [4, 3]]
Function signature:
def transpose(matrix: List[List[int]]) -> None:
#Steps#
1. Iterate through the rows of the inpu... | codefeedback |
Write code to print the prime numbers in a given range using a time complexity of O(n log(log n)) and without using any built-in functions or libraries for checking prime numbers. | codefeedback |
Generate a sorted list of numbers in an array using insertion sort, without using any built-in sorting functions or methods. Additionally, the algorithm should be implemented in a recursive manner.
arr = [5, 8, 1, 7, 2, 10, 3] | codefeedback |
Create a HTML page with text "Hello, World!" and a button that changes the text to "Goodbye, World!" when clicked. Additionally, implement the following features:
1. Add a counter that keeps track of the number of times the button has been clicked. Display the count below the text.
2. Limit the maximum count to 10. On... | codefeedback |
Design a program to compute the median of an array of n integers, where n is an odd number greater than 1. The array may contain duplicate elements.
Time complexity: O(n)
Space complexity: O(n)
The program should not use any built-in sorting functions or data structures. | codefeedback |
Manipulate a large spreadsheet with Python to identify duplicates in multiple columns (A, B, C, and D) and display the rows where the duplicates are found. Additionally, the program should also calculate the average of the values in column E for each unique combination of columns A, B, C, and D, and display the results... | codefeedback |
Create a function that finds the length of the longest substring that does not contain duplicate characters. The function should handle cases where the input string contains non-alphabetic characters and return an error message for such cases. Additionally, the function should ignore duplicate characters that are withi... | codefeedback |
Create a code to print each word of a sentence on a new line, excluding any duplicate words. The sentence can contain special characters and multiple spaces between words. The code should be able to handle sentences of length up to 10^5 words efficiently. | codefeedback |
Write a parser to convert an XML document to a dictionary. Your implementation should handle nested elements and attributes. Additionally, it should support both opening and self-closing tags. The resulting dictionary should maintain the hierarchical structure of the XML document.
You may assume that the XML document... | codefeedback |
Write a JavaScript code to merge two sorted arrays into a third array, ensuring that no duplicates are present. The merged array should be sorted in descending order. The input arrays must contain only unique elements and have a maximum length of 100. The merged array should have a maximum length of 200. If the input a... | codefeedback |
Write a Java program to convert a binary string to a decimal number. The binary string can have a maximum length of 64 characters. Additionally, the program should handle cases where the binary string contains leading or trailing whitespace characters.
#Additional Requirements#
1. The program should validate that the ... | codefeedback |
Write a SQL query to select the first 10 records from a table called "Employees" where the employee's salary is greater than 5000, their hire date is within the last year, and their job title is either "Manager" or "Director". | codefeedback |
Create an HTML page that has an input field and a button. When the button is clicked, the text from the input field should be printed to the console. Additionally, the input field should only accept alphanumeric characters, should have a maximum character limit of 20, and should not allow the user to input more than 20... | codefeedback |
Create an HTML page with a table containing ten columns and twenty rows. The table should have alternating row colors, with odd rows having a light grey background and even rows having a white background. Additionally, the table should have a header row that spans across all columns and is centered. The header row shou... | codefeedback |
Create a .Net console application to print a personalized greeting according to the user’s input. The program should take the user's name as input and print a greeting message that includes their name. The program should validate the input to ensure that the user has entered a valid name. A valid name should consist of... | codefeedback |
Write a Java method that takes a string and returns a copy of the string with all lowercase letters replaced with uppercase letters and vice versa. The method should also remove any spaces, punctuation marks, and special characters in the string and return the modified string.
Constraints:
- The input string will cont... | codefeedback |
Create a Python program that removes all occurrences of a given item from a list, but the program should not use the built-in 'remove' function and should have a time complexity of O(n). | codefeedback |
Write a Java program to multiply two large numbers of any length, but without using the `*` operator or any built-in libraries for multiplication.
Note: You can assume that the two numbers will be positive and will not exceed the maximum value of `Long`. | codefeedback |
Develop a Java program to rotate a two-dimensional array clockwise by 90 degrees. Below is an incorrect implementation of the solution.
```java
public class ArrayRotation {
public static void rotateArray(int[][] matrix) {
int n = matrix.length;
for (int layer = 0; layer < n / 2; layer++) {
... | codefeedback |
Create a SQL query to select the name, email, and department of employees who have been with the company for more than 10 years and are earning a salary above the average salary of their department, excluding those with a job title of "Manager". Additionally, sort the result by department in ascending order and by sala... | codefeedback |
Create a code to check if a number is a Fibonacci number or not. Additionally, if the number is not a Fibonacci number, the code should return the closest Fibonacci number that is smaller than the given number. | codefeedback |
Write a C++ program that calculates the mean, median, and mode of an array of integer numbers. The array may contain duplicates.
The mean is the average of all the numbers in the array. To calculate the mean, add up all the numbers in the array and then divide the sum by the total number of elements.
The median is th... | codefeedback |
Create an algorithm using JavaScript that finds the largest prime number in an array, but do not use the built-in Math.max() method. The array may contain negative numbers.
[-5, 3, -8, 2, 10] | codefeedback |
Create a web application that allows users to create an account and log in. Once logged in, users should be able to upload an image and apply a variety of image filters to it. The application should also allow users to save the edited image to their account. Additionally, users should only be able to save images that h... | codefeedback |
Create an HTML page with a table that displays the given data. The table should have a fixed width of 500 pixels and should be centered on the page. Each row in the table should have alternating background colors (light gray and white). The dessert names should be displayed in uppercase letters, and the calorie values ... | codefeedback |
Create a class in Java that takes two arguments, a name of type String and an id of type int. The name should be limited to a maximum length of 20 characters and should only consist of alphabetic characters. The id should be a positive integer between 1 and 1000.
In addition, the name should be converted to lowercase ... | codefeedback |
Write an algorithmic query in SQL to find the number of working days since each employee joined the organization, taking into account leap years, weekends (Saturdays and Sundays), and the possibility of employees joining on a future date. | codefeedback |
Using the Java stream API, create a program that takes a list of integers and returns the number that appears most often in the list. However, you are not allowed to use any loops, conditional statements (if/else), or any stream API methods that directly solve the problem (such as `collect`, `groupingBy`, `count`, etc.... | codefeedback |
Create a JavaScript program that takes in an array of boolean values and toggles each value. Return the modified array. The program should also check if the length of the input array is odd and throw an error if it is not. Additionally, the program should throw an error if any of the boolean values in the input array a... | codefeedback |
Create a JavaScript function that takes in an array of objects as an argument and counts the occurrence of a given element based on a specific property of the objects. The function should only count the occurrence of the given element if it is an exact match in terms of case. For example, if the given element is "A" an... | codefeedback |
Code a nested loop to print out the multiplication table of a given number, ensuring that the table only includes the multiples of 3 and ends at the 20th multiple. Use the number 7. Additionally, the table should only display the multiples of 3 that are also divisible by 2. | codefeedback |
Using the MapReduce programming model, calculate the total number of purchases made by customers who have spent more than $500 in a given dataset. Additionally, implement error handling to account for any invalid data inputs and provide appropriate error messages. | codefeedback |
Write a function that creates a random 6 digit pin using the following criteria:
#Additional information#
- The pin must consist of only prime numbers.
- The first two digits must be odd prime numbers.
- The last two digits must be even prime numbers.
- The pin must not have any repeating prime digits.
- The pin shoul... | codefeedback |
Create an HTML page with a form to sign up for a newsletter. Implement client-side validation to ensure that the user enters a valid email address and that all required fields are filled out before submitting the form. Additionally, implement server-side validation to prevent duplicate sign-ups from the same email addr... | codefeedback |
Generate a random 10 character password using the following conditions:
1. The password must contain at least two uppercase letters, two lowercase letters, two digits, and two special characters (!, @, #, $, %, ^, &, *, or +).
2. The password cannot contain any repeated characters.
3. The password must start with a lo... | codefeedback |
Edit the following PHP code to add a custom header to the response and handle potential errors appropriately. Additionally, handle any errors that may occur during the encoding process and display an appropriate error message if necessary.
```php
<?php
header("Content-Type: application/json");
// Generate rando... | codefeedback |
Create a Python script that takes a list of numbers as an argument and returns the maximum number in the list. The script should also handle cases where the input list may contain duplicate numbers and should return the maximum number without counting duplicates multiple times. Additionally, the script should ensure th... | codefeedback |
Develop an algorithm to find the greatest common factor (GCF) of three prime numbers in Python. The algorithm should have a time complexity of O(n), where n is the largest prime number among the three. | codefeedback |
Create an HTML page that displays a table of the 10 most visited countries in the year 2020, based on data from multiple travel agencies. Each travel agency provides the number of visitors for each country.
Implement a function that takes in an array of objects, where each object represents the data from one travel a... | codefeedback |
Write a Python program to find all prime numbers up to a given number, n. The program should return a list of the prime numbers.
You are required to use the Sieve of Eratosthenes algorithm to solve this problem.
The Sieve of Eratosthenes algorithm works as follows:
1. Create a list of boolean values, is_prime, of len... | codefeedback |
Suggest a condition for including an element in an array such that it must be a prime number, its index in the array must be a multiple of 3, and the sum of its digits must be divisible by 5. | codefeedback |
Generate a function to sort a 2-dimensional list in Python by the values of the second element in each sublist, while also handling cases where the second element is a string or a negative number. The function should have a time complexity of O(n log n) and should not use any built-in Python sorting functions.
Additio... | codefeedback |
Generate a list of prime numbers between two numbers A and B (both inclusive) using a segmented sieve algorithm. The time complexity should be less than O((B-A+1)log(log(B))). Additionally, the algorithm should use multithreading to speed up the computation process. | codefeedback |
Code a HTML form that collects the user's first name, last name, age, email address, phone number and an optional message. Validate the input fields to ensure that the email address is in a valid format, the age is a positive integer between 18 and 65, and the phone number is in a valid format with a country code. Disp... | codefeedback |
Implement the in-place insertion sort algorithm in Java to sort an array of integers in non-decreasing order.
In addition to the sorting functionality, the algorithm should also remove any duplicate elements from the sorted array, ensuring that each element appears only once.
To accomplish this, modify the original... | codefeedback |
Construct a network to recognize handwritten digits using a convolutional neural network in TensorFlow. Your solution should include at least 5 convolutional layers, each with a different filter size, and use the Adam optimizer for training. Additionally, your network should achieve a minimum accuracy of 98% on the MNI... | codefeedback |
Suggest a code for removing the first element from an array and then shifting all the remaining elements to fill the empty space. However, instead of using built-in array functions, you are required to implement the shifting logic manually without using any additional data structures. | codefeedback |
Rewrite the following python program to convert UTC time to local time and display it in a specific format. Additionally, include error handling for invalid input.
from datetime import datetime, timedelta
import pytz
def convert_utc_to_local(utc_time_str, timezone_str):
try:
# Step 1: Parse the input UTC ... | codefeedback |
Develop a function to calculate the median of a set of numbers in C#.
Write a function named "CalculateMedian" that takes in an array of integers and returns the median value.
The median is defined as the middle value in a sorted list of numbers. If the list has an odd number of elements, the median is the value at... | codefeedback |
Write a script in JavaScript for reversing an array without using any built-in array manipulation methods or additional data structures. The solution should have a time complexity of O(n) and a space complexity of O(1). Additionally, you are not allowed to use any loop structures such as for, while, or do-while. | codefeedback |
Suggest code for finding the maximum element in a Python dictionary based on a specific condition. The condition is that the maximum element should be determined based on the sum of the values of its nested dictionaries, while also considering the sum of the values in its immediate child dictionaries. Additionally, the... | codefeedback |
Design and code a responsive HTML table that displays a list of students and their corresponding information such as name, age, grade, and contact details. Implement a sorting functionality that allows users to sort the table based on any column in ascending or descending order.
The table should also include a search ... | codefeedback |
Suggest a way to remove duplicate characters from a string in JavaScript, without using any built-in array methods or regular expressions, and with a time complexity of O(n). | codefeedback |
Write a script in PHP for converting a string to lowercase, but without using the built-in strtolower() function and without using any loop or recursion. | codefeedback |
Suggest an algorithm for deleting an element from an array at a given index, while maintaining the order of the remaining elements. The time complexity should be O(n), where n is the length of the array. Additionally, the algorithm should use only constant space, without creating any additional data structures.
To fur... | codefeedback |
Find the kth smallest element in an array. The array consists of integers only and the size of the array is given. You are not allowed to use any sorting algorithms or built-in functions to solve this problem. Additionally, you must solve this problem using only a constant amount of extra space. You must come up with a... | codefeedback |
Suggest a function in JavaScript for repeating a given string a specified number of times, but the string must contain only unique characters and the number of times to repeat must be a prime number. Additionally, the function should handle cases where the given string may contain non-alphanumeric characters and whites... | codefeedback |
Suggest a loop in JavaScript for traversing an array of objects and printing out specific properties of each object. However, the loop should only print out properties that have a numeric value greater than 10.
Additional Instructions:
1. The array of objects should have at least 10 objects.
2. Each object should have... | codefeedback |
Output the number of items in a hashmap with key-value pairs ["Mon", "Monday"], ["Tue", "Tuesday"], ["Wed", "Wednesday"], but you are not allowed to use any built-in functions or methods for counting the items. Additionally, you are not allowed to use any loops or recursion to iterate through the hashmap. | codefeedback |
Create an SQL query to get the average price of all the products with a quantity greater than 10 and less than 50, and whose product name starts with the letter "A" or ends with the letter "Z" in the products table. | codefeedback |
Write a script for reversing the order of vowels in a string in Python.
You are given a string as input. Your task is to reverse the order of vowels in the string.
For example, if the input string is "hello world", the output should be "hollo werld".
To solve this problem, you can follow these steps:
1. Initialize a... | codefeedback |
Edit the following Java program to output the product of the two numbers, but the product should only be calculated using bitwise operators.
int firstnum = 5;
int secondnum = 10; | codefeedback |
Write a code to get the user input for two positive integers less than 1000 and print the sum of the two numbers. Ensure that the code handles invalid inputs gracefully and provides an appropriate error message.
Additionally, implement a feature that allows the user to continue entering numbers and computing the sum u... | codefeedback |
Create a function in JavaScript that takes two parameters: a start number and an end number. The function should return an array of all prime numbers within the given range.
Additionally, you should implement the Sieve of Eratosthenes algorithm to find the prime numbers efficiently. This algorithm works by iteratively... | codefeedback |
Explain the concept of constants in Java and provide an example of how to declare and use a constant in a Java program. Additionally, explain the differences between final variables and constant variables in Java. | codefeedback |
Write a JavaScript function that takes a string as input and returns the reverse of the string. You are not allowed to use any built-in string reverse function or any other built-in function that directly solves the problem. You should implement your own logic to reverse the string. Your function should also handle any... | codefeedback |
Write a SQL query to select all Colleges from the table "Universities" whose enrollment is higher than 10,000 students, whose location is in a city with a population greater than 1 million, and whose average GPA of enrolled students is above 3.5. | codefeedback |
Create a Python function to insert a new element in a list at the given index, but you are not allowed to use any built-in list methods such as `insert()` or `append()`. You can assume that the list and index are valid inputs. Additionally, the function should handle the case when the given index is out of range, by ei... | codefeedback |
Using Java, create a method that takes an array of integers and returns the maximum value. However, you are not allowed to use any built-in functions or methods that directly find the maximum value. You must implement your own algorithm to find the maximum value. Additionally, your algorithm must have a time complexity... | codefeedback |
Convert the following JSON data to an HTML table, but only include fruits that start with the letter "a" and vegetables that start with the letter "p". Additionally, sort the table rows in alphabetical order based on the names of the fruits and vegetables.
{
"fruit": ["apple", "apricot", "banana", "orange"],
"vege... | codefeedback |
Using JavaScript, create a function that takes in an array of numbers as the first argument and a single number as the second argument. The function should return the number from the array that is closest to the second argument, but only if it is larger than the second argument. If there is no number in the array that ... | codefeedback |
Develop a function to remove the given string from another string while also ignoring the case sensitivity.
String to remove: "cat"
String to modify: "The Crazy CAT jumped to the roof"
Additional requirement 1: The function should also replace any occurrence of the word "cat" within another word with an empty string.
... | codefeedback |
Edit the following line of code to turn the sentence into plural form. Instead of simply adding an "s" to the word "friend", add an "es" to the word "one". Additionally, ensure that the first letter of the sentence is capitalized and that there is a punctuation mark at the end of the sentence. sentence = "i have ones f... | codefeedback |
Implement an iterator in Python for the following string, but with the restriction that it can only iterate over lowercase letters. Additionally, the iterator should skip any duplicate characters and should return each character in reverse order. The iterator should also keep track of the number of times each character... | codefeedback |
Explain the concept of tokenization in relation to natural language processing and provide a piece of code in Python that demonstrates how tokenization can be implemented. Additionally, provide a piece of erroneous code that showcases a common mistake when implementing tokenization. | codefeedback |
Write a block of code to convert a given string to upper case.
String to convert: "The Quick Brown Fox Jumped"
Additional Requirements:
1. Your solution should not use any built-in functions or methods that directly convert a string to upper case.
2. Your solution should handle all types of characters, including spe... | codefeedback |
Develop a program to generate the Fibonacci sequence up to the nth term.
Requirements:
1. The program should be able to handle very large values of n, up to 10^18.
2. The program should have a time complexity of O(log n) or better.
3. The program should use constant space, i.e., it should not use any additional data s... | codefeedback |
Implement a modified version of bubble sort in Python that only sorts the elements in the even indices of the input list, and also ignores negative numbers in the sorting process. | codefeedback |
Write an SQL query to select the item names, prices, and total quantities sold from an inventory table. Additionally, include a calculated column that displays the average price of each item. Ensure that the query only considers items with a quantity sold greater than 100 and a price higher than $50. | codefeedback |
Write a function definition in JavaScript that calculates the factorial of a number. The factorial of a number is the product of all positive integers less than or equal to the number. The function should have a time complexity of O(n) and should not use any built-in JavaScript functions or libraries. | codefeedback |
Write a Java program that takes an array of integers as input and prints the sum of all the positive integers to the console. However, you are not allowed to use any built-in arithmetic functions or loops. The time complexity of your solution should be O(n) and the space complexity should be O(1).
Example:
Input: [2, ... | codefeedback |
Write an SQL query to find all employees with a salary greater than $5000, have been employed for more than 5 years, and have at least 2 promotions during their employment period. | codefeedback |
Compute the sum of all the prime numbers in an array of integers in Java, but with the following additional requirements:
1. The time complexity of the solution should be O(n^2), where n is the length of the array.
2. The space complexity of the solution should be O(1), i.e., no additional space should be used other t... | codefeedback |
Write a SQL statement to select the names of employees whose first name begins with 'A' and their last name begins with 'S', who have a salary greater than $50,000 and have been with the company for at least 3 years. Additionally, exclude any employees whose job title is 'Manager' or 'Director'. | codefeedback |
Create a Python program that can dynamically change the text color of a button based on user input. The program should allow the user to enter a color code or select a color from a predefined list, and then update the text color of the button accordingly. The program should also include error handling to ensure that on... | codefeedback |
Write a Java program to sort the following array of integers using Quick Sort.
int arr[] = {4, 3, 6, 2, 5, 1};
Additional requirements:
1. The program should sort the array in descending order.
2. The program should use an iterative implementation of Quick Sort instead of recursive implementation.
3. The program shou... | codefeedback |
Write a Python method to generate a random string of length 10 with the following additional constraints:
1. The generated string must contain at least one uppercase letter and one lowercase letter.
2. The generated string must contain at least one digit and one special character (!, @, #, $, %, &, *, ?, +, -).
3. The ... | codefeedback |
Write a program that converts the following string to uppercase without using any built-in string methods or any other built-in functions that directly manipulate strings. Additionally, you are not allowed to use any external libraries or modules.
#Additional Instructions#
1. You must implement your own function to co... | codefeedback |
Write a program that creates a navigation bar with 5 links and displays it on a web page. The program should use HTML, CSS, and JavaScript to achieve the following requirements:
1. The navigation bar should be responsive and adjust its layout based on the screen size, ensuring that all links are visible and accessible... | codefeedback |
Given a large JSON file containing information about cities including their name, population, and coordinates, write a Python program to efficiently find and print the names of the top 10 cities with the highest population within a specified distance from a given set of coordinates. The program should be able to handle... | codefeedback |
Write a PHP code to find the first day of the current month in a leap year, without using any built-in date functions or libraries. The code should be optimized to have a time complexity of O(1) and a space complexity of O(1). | codefeedback |
Write a JavaScript function that takes two parameters: an array of positive integers and a single positive integer. The function should return an array containing only the elements of the given array that are divisible by the second parameter without any remainder. The function should also remove any duplicates from th... | codefeedback |
Suggest an algorithm to solve the N queens problem with the additional constraints that no two queens should be in the same row, column, or diagonal, and at least one queen should be placed in each quadrant of the chessboard. | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.