instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Define a function that takes in an integer n and a string s, and returns the string s repeated n times. The function should also check if n is a positive integer and throw an error if it is not. Additionally, the function should validate that s is a non-empty string and throw an error if it is empty. | codefeedback |
How would you create a list of 100 elements by calling the range() function, but only include odd numbers? | codefeedback |
Using Python, create a function that takes two parameters: the month (as an integer between 1 and 12, inclusive) and the year (as a positive integer between 1 and 9999, inclusive) and returns the number of days in that month. The function should handle leap years correctly and should raise a ValueError if the month or ... | codefeedback |
Using Java, write a program to check whether an integer is prime or composite. The program should also validate that the input is within the range of -10^6 to 10^6, inclusive. If the input is outside this range, the program should display an error message and ask the user to enter a valid integer. Finally, the program ... | codefeedback |
Write a Swift program that prompts the user to enter two integers and prints out the maximum value of the two. The program should also check if the entered values are within the range of -100 to 100 (inclusive) and provide an error message if the values are outside this range. Additionally, the program should keep trac... | codefeedback |
## Fragment Counter ##
Write a function `fragment_counter` that takes in a string as input and returns the number of fragments in the string.
A fragment is defined as a sequence of consecutive alphabetic characters that are separated by whitespace, punctuation, or a digit.
The function should satisfy the following... | codefeedback |
Write a function to find all possible subsets of a given string.
#Updated Solution Explanation#
To solve this problem, we can use a recursive approach.
1. First, we need to check if the given string is empty. If it is, we have reached a valid subset, so we print it.
2. If the string is not empty, we have two options: ... | codefeedback |
Using given HTML code, make the font color of the 2nd paragraph blue. Additionally, you must use JavaScript to dynamically change the font color instead of applying a static style in the HTML code. However, you are not allowed to directly access the paragraph element by its id or class name. You must find the 2nd parag... | codefeedback |
Create a C++ program to sort an array using selection sort algorithm.
However, there are multiple errors in the code. Identify and fix the errors to correctly sort the array.
The program should take an array of integers as input and sort the elements in ascending order. The sorting should be done using the selection... | codefeedback |
Write a script in JavaScript to print the first 50 prime Fibonacci numbers, where each prime Fibonacci number is greater than 100. | codefeedback |
Write a Rust program to convert a string to title case, considering that the input string may contain punctuation marks and special characters, and the program should preserve the case of any acronyms or abbreviations within the string. Additionally, the program should handle multi-word acronyms or abbreviations by cap... | codefeedback |
Using pandas, create a dataframe with four columns and one million rows. | codefeedback |
Read an array of positive integers from stdin and find the maximum prime number in it. Additionally, you need to find the second maximum prime number in the array.
To solve this problem, you should follow these steps:
1. Read the array of positive integers from stdin.
2. Initialize two variables, `maxPrime` and `secon... | codefeedback |
You need to sort a singly linked list in ascending order. Each node of the linked list contains an integer value. Implement a function that sorts the linked list in place.
The input linked list is guaranteed to have at least two nodes.
Example:
Input: head = 10 -> 8 -> 5 -> 12 -> 15
Output: head = 5 -> 8 -> 10 -> 12 ... | codefeedback |
Create an SQL query to return the titles of all books written by a given author, along with the number of pages in each book. The query should also include the average rating of each book, rounded to the nearest whole number. The author's name should be entered as a parameter when executing the query.
Author: John Doe | codefeedback |
In Ruby, write a method that takes a string and prints all possible combinations of the characters in reverse order. The method should have a time complexity of O(2^n), where n is the length of the input string. Additionally, the method should not use any built-in Ruby methods for generating permutations or combination... | codefeedback |
Explain the advantages and disadvantages of using a circular doubly linked list over a singly linked list in terms of time complexity and memory allocation. Provide a code example demonstrating the implementation of a circular doubly linked list. | codefeedback |
Code a PHP program to detect if a URL is valid or not, ensuring that it follows the HTTP/HTTPS protocol, has a valid domain name and TLD, includes at least one query parameter in the form of key-value pairs, and performs a DNS lookup to check if the domain name exists. Additionally, implement a check to see if the URL ... | codefeedback |
Given a string, reverse the order of words and then print the string. Additionally, reverse the characters within each word. The input string may contain alphabetic characters, spaces, punctuation marks, and special characters. The output should maintain the same capitalization as the input.
Example:
Input: "Hello, Wo... | codefeedback |
In Java, convert an integer array to a string, while removing any duplicate elements and maintaining the order of the original array.
[1, 2, 2, 3, 4, 4] | codefeedback |
In Java, create a method to detect if a number is a palindrome. Additionally, you should implement the following features:
1. The method should handle negative numbers as well.
2. The method should also handle numbers with leading zeros (e.g. 00100 should be considered as a palindrome).
3. The method should handle numb... | codefeedback |
Write a Swift function to parse a JSON string into a dictionary, but without using any JSON parsing libraries or built-in functions. Additionally, the function should handle nested JSON objects and arrays within the JSON string. | codefeedback |
Write a Perl program to generate the Fibonacci series in reverse order, but the program must use a recursive function to calculate each Fibonacci number. | codefeedback |
Create a python script that connects to a MongoDB database and outputs the average age of users who have a salary greater than $50,000 and are located in a specific city provided as input. | codefeedback |
Write a program in Python to perform CRUD operations on a MongoDB database using only a single function. The function should be able to handle all CRUD operations (create, read, update, delete) and should take in the following parameters:
1. The MongoDB connection URL
2. The name of the database
3. The name of the col... | codefeedback |
Create a GUI interface for a multiplayer card game using PyQt5. The interface should allow players to customize the game rules, such as number of players, deck size, and the ability to choose from multiple game modes. Additionally, implement a feature that allows players to chat with each other during the game, includi... | codefeedback |
Reverse the following Scala list while also maintaining the original order of odd and even numbers: ``List(1, 2, 3, 4, 5, 6, 7, 8)`` | codefeedback |
Rewrite the following Java loop as a compact list comprehension, without using any built-in array functions or methods.
int[] array = {1, 2, 3, 4, 5};
int[] array2 = new int[array.length];
for(int i=0; i<array.length; i++) {
if(array[i] % 2 == 0) {
array2[i] = array[i] * 2;
} else {
array2[i] = ... | codefeedback |
Write a SQL query to delete all entries that have a value of "NULL" in the field "name" and a value of "0" in the field "age". Additionally, ensure that the deletion operation is performed in a single transaction to maintain data integrity.
#Reasoning Steps#
1. Begin a new SQL transaction.
2. Check if the database tab... | codefeedback |
Replace the placeholder in the sentence below with the appropriate method.
Use the __________ function to convert the string to lowercase. Additionally, handle cases where the input string is empty or contains non-alphabetic characters by returning an empty string.
#Erroneous Code#
Use the capitalize() function to con... | codefeedback |
Write a C++ program to read an array of integers from the user, sort the array in ascending order, and then print the sorted array.
Constraints:
- The maximum size of the array is 10^6.
- The integers in the array can range from -10^9 to 10^9.
Additional requirements:
- Implement a sorting algorithm with a time compl... | codefeedback |
Write a shell script that prints out the directory this command was run from, as well as all subdirectories and files within it, recursively. The script should include the following additional features:
1. The ability to filter and display only specific types of files, such as only text files or only image files. The ... | codefeedback |
Create a deep convolutional neural network in PyTorch to classify images in the CIFAR-10 dataset. Additionally, implement a data augmentation technique such as random cropping or flipping to improve the model's performance. | codefeedback |
Write a SQL query to find all students who have a GPA greater than 3.5 and are enrolled in at least 5 courses, excluding any students whose first names start with the letter 'A'. | codefeedback |
List all properties of a JavaScript object called ``person`` recursively. The object may have nested objects as properties, and all properties, including nested properties, should be listed. The solution should not use any built-in JavaScript functions such as `Object.keys()` or `Object.getOwnPropertyNames()`. The time... | codefeedback |
Create a class called Vehicle in Python with attributes for type (car, truck, motorcycle etc.), make, model, year, speed, and color. The color attribute should only accept values from a predefined list of colors, such as red, blue, green, yellow, and black. Additionally, the speed attribute should have a minimum value ... | codefeedback |
Name and explain four of the main components of a basic HTML page, ensuring that the page is responsive, includes a navigation bar with dropdown menus, and supports multiple screen sizes with different layouts for desktop and mobile devices. | codefeedback |
Modify the following code so that it prints the Fibonacci numbers up to the given number x, while also excluding any Fibonacci numbers that are divisible by 4. Additionally, the program should calculate and print the product of all the Fibonacci numbers generated. x = 20 | codefeedback |
Devise a recursive solution to the problem.
Find the sum of all prime numbers from 1 to N. | codefeedback |
Write a nested loop to iterate over all elements of a multi-dimensional array and calculate the sum of all odd numbers in the array.
Create a variable called "sum" and set it to 0.
Using a nested loop, iterate over each element in the multi-dimensional array.
Within the inner loop, check if the current element is od... | codefeedback |
Using MongoDB, create a query to find all documents where the status is "ACTIVE" and the value of a specific field called "priority" is greater than 5, but also make sure that the documents are sorted in descending order based on the "priority" field.
Additionally, only retrieve the documents where another field calle... | codefeedback |
Create a function that takes in a list of integers and returns the count of even numbers in the list. If the input is an empty list or None, the function should return -1.
Example:
Input: [2, 5, 8, 10, 11, 12]
Output: 4
Input: [1, 3, 5, 7, 9]
Output: 0
Input: [0, -2, -4, -6, 1, 3, 5, 7, 9]
Output: 4
Input: []
Outpu... | codefeedback |
Design a program to search a list for a specified item and return the index of the first occurrence. If the item is not found in the list, the program should return -1. Additionally, the program should be able to handle lists containing duplicate elements. The program should have a time complexity of O(log n) for searc... | codefeedback |
Identify the indices of all even numbers in an array. The array may contain both positive and negative integers. If an even number appears multiple times in the array, consider all occurrences and return the indices in ascending order. Implement your solution in a way that has a time complexity of O(n) and a space comp... | codefeedback |
Given a matrix of size n x m, output the sum of all elements in the matrix. However, you must exclude any negative numbers in the matrix from the calculation. Additionally, you need to find the minimum positive element in each row and exclude it from the sum as well.
Constraints:
- The matrix can contain both positive... | codefeedback |
Generate a list of unique prime numbers between 10 and 50, where the sum of all the numbers in the list is a multiple of 3. Additionally, the list must be sorted in ascending order and the algorithm should have a time complexity of O(n log(log n)). | codefeedback |
Design a function to get the user input for a list of numbers and print the maximum among them, without using any built-in functions or libraries to find the maximum value.
Additional requirements:
1. The function should handle both positive and negative numbers.
2. The function should handle floating-point numbers.
3... | codefeedback |
Rewrite the given string 'Hello World' to 'World Hello' using only constant space complexity (O(1)) and without using any built-in string manipulation functions. Additionally, the solution should have a time complexity of O(n), where n is the length of the string. | codefeedback |
Given a string of length n, find the number of distinct continuous substrings in the string, where a distinct substring is defined as a substring that does not contain any duplicate characters.
Constraints:
- 1 ≤ n ≤ 10^6
- The string can contain uppercase and lowercase letters, digits, and special characters.
- The s... | codefeedback |
What type of neural network architecture, typically used for natural language generation tasks, employs both an encoder and a decoder component, and requires the use of attention mechanisms for improved performance? | codefeedback |
Write a code to make an API call to a remote server and retrieve a list of users. Each user should have the following attributes: name, age, email, and address. Parse the response and display the information of each user in a formatted manner. Additionally, implement error handling to handle any possible exceptions tha... | codefeedback |
Create a function that finds all anagrams of a given word while also ensuring that the length of each anagram is less than or equal to the length of the given word. The function should return a list of anagrams in alphabetical order.
word = "abbac"
# Erroneous Code
def find_anagrams(word):
"""
This function f... | codefeedback |
What data structure is commonly used to represent the hierarchical structure of XML documents, and how can you efficiently search for specific elements within this structure? Additionally, describe a situation where using this data structure may not be the most efficient approach and suggest an alternative data structu... | codefeedback |
You are given a large codebase with multiple errors. Design an automated error tracking system that efficiently finds and prioritizes the severity of these errors. You need to consider the following points:
1. Error Detection: Develop a mechanism to automatically detect errors in the codebase. This can include impleme... | codefeedback |
Rewrite the given test question to increase the difficulty:
Describe a multi-threaded application in Python that reads from and writes to a shared resource. Ensure thread synchronization by using a combination of locks, semaphores, and condition variables. Explain how you would debug this application using the `pdb` m... | codefeedback |
Please write a function that takes in a dictionary as input and returns a list of the dictionary keys sorted in ascending order.
#Additional Instructions#
1. The code should run in O(n log n) time complexity, where n is the number of keys in the dictionary.
2. Do not use any built-in sorting functions or methods to so... | codefeedback |
Write a function that takes in a string and a positive integer N, and prints the string N times. The function should also check that the string only contains letters (a-z or A-Z) before printing, and if it contains any other characters, it should raise an exception with a custom error message. Additionally, the functio... | codefeedback |
Suggest a faster way to get a sublist from a given list, considering that the sublist needs to satisfy the following conditions:
1. It should contain elements greater than a certain value.
2. It should contain elements that are divisible by another certain value.
3. The sublist should be sorted in descending order.
Ad... | codefeedback |
Find the area and circumference of a circle with radius 2, using only mathematical operations and without using any built-in functions or libraries. The solution should be implemented in a programming language of your choice and include error handling for invalid inputs. | codefeedback |
Given a list of numbers, sort them in increasing order without using any built-in sorting functions or libraries. The solution should have a time complexity of O(n^2), where n is the length of the list, and a space complexity of O(1).
Additionally, the solution should be stable, meaning that elements with equal values... | codefeedback |
You are given a large text file with multiple lines of data. Each line contains a combination of alphanumeric characters and symbols. Write a Python function that uses regular expressions to extract all valid email addresses from the text file. Assume that an email address consists of a local part followed by the "@" s... | codefeedback |
Write a Python program to create a function that takes two numbers as arguments and returns a list of all prime numbers between them. The program should also display the total count of prime numbers and the sum of those prime numbers.
start_range = 2
end_range = 100 | codefeedback |
Create a python script that takes three required parameters 'x', 'y' and 'z' and prints the result of x * y * z. The values of 'x', 'y', and 'z' must be positive integers and their sum must be less than or equal to 100.
In addition, the script should handle the following scenarios:
1. If any of the parameters is not ... | codefeedback |
Write a Python program to shuffle the items of a given list in random order without using the built-in shuffle function. The program should have a time complexity of O(n) and a space complexity of O(1).
list_elements = [1, 2, 3, 4, 5] | codefeedback |
Write a SQL statement to retrieve the average salary of all employees for each department, while also displaying the department name and the number of employees in each department. | codefeedback |
Write a Python program to convert an integer to a Roman numeral. The program should be able to handle input numbers up to 3999 and must handle negative input numbers as well. Additionally, the program should validate the input and display an error message if the input is not a valid integer. | codefeedback |
Write a Python program to compare two given lists and return True if their contents are the same, while also ensuring that the order of elements is also the same. The program should have a time complexity of O(n), where n is the length of the lists. Additionally, the program should use only constant space, i.e., it sho... | codefeedback |
Create a function in Ruby to input an array and remove all the elements of the array. However, you are not allowed to use the built-in `clear` method of the array class. Additionally, your implementation should have a time complexity of O(n) and should not use any temporary arrays or additional data structures. | codefeedback |
Without using any built-in functions, generate a Python code to remove the duplicated elements in a list while maintaining the original order of the elements. Additionally, implement the code in a time complexity of O(n), where n is the length of the list. | codefeedback |
Suggest a Python code for printing the sum, minimum, and maximum of a given list. However, the code should be able to handle lists containing both numbers and strings, and should exclude the strings while calculating the sum, minimum, and maximum. Additionally, the code should handle lists that contain nested lists as ... | codefeedback |
Explain the concept of polymorphism in object-oriented programming and provide an example code snippet to demonstrate its implementation. Additionally, identify and correct any errors in the code snippet provided below:
```python
class Animal:
def __init__(self, name):
self.name = name
def sound(self)... | codefeedback |
Edit the given code to delete a node from a linked list in constant time complexity, without using a temporary variable and without using the "next" pointer of the previous node.
void deleteNode(struct node *node)
{
if(node == NULL || node->next == NULL)
return;
// Find the last node in the linked l... | codefeedback |
Write a SQL statement to sort a list of employees in descending order based on their salary. Additionally, display the number of years each employee has been with the company and include a calculated column to show the median salary of all employees. | codefeedback |
Write a python script to print out a list comprehension that prints out all the prime numbers in a given range from 1 to 100, along with their sum and product. | codefeedback |
Write a MongoDB query to find which roles have both Permission 2 and Permission 3, and sort the result in descending order by the number of users assigned to each role. Additionally, include the total number of users assigned to each role in the result.
To increase the difficulty, you can add the following steps to th... | codefeedback |
Select all distinct employee names from the given table, excluding any names that start with the letter "A", have more than 5 characters, and contain the letter "e". | codefeedback |
Write a code for extracting the last n prime numbers from a list of positive integers, removing any duplicates.
List: [1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 9, 10, 11, 11], n = 3 | codefeedback |
Suggest a Python code for sorting a list of dictionaries based on ascending order of a given key. The key should be case-insensitive, meaning that the sorting should not be affected by the capitalization of the key's value. Additionally, if two or more dictionaries have the same value for the given key, they should be ... | codefeedback |
Create a complete JavaScript code that uses the fetch() API to make a POST request to a specified URL (e.g., https://api.example.com/endpoint) with the following payload:
```
{
"username": "john",
"password": "secret"
}
```
The code should handle the following scenarios:
1. Network issues: If there is a network err... | codefeedback |
Create a SQL query to list all the customers from the US who have made at least 5 purchases in the last month, have a total purchase amount greater than $1000, and have not purchased any products that are currently out of stock. | codefeedback |
Write a PHP script to compare two strings and return the number of characters and words which are common in both strings, while ignoring case sensitivity. Additionally, you must exclude any common words that appear in a common dictionary.
The script should perform the following steps:
1. Convert both strings to lower... | codefeedback |
Write a Python program to find the sum of all even integers from 1 to 100, while excluding any multiple of 3 and 5 from the summation.
Additional Requirements:
- Use a loop to iterate through the numbers from 1 to 100.
- Use conditional statements to check if a number is even and not a multiple of 3 or 5.
- Use a vari... | codefeedback |
Create a web application that allows users to search for books and sort the search results based on different criteria. The application should have the following features:
1. A navigation bar with a heading, a search field, and a dropdown menu.
2. The search field should allow users to enter a keyword and search for b... | codefeedback |
Write a query to find the third highest salary of an employee in the Employee table, considering only employees who have been with the company for at least 2 years. | codefeedback |
Create a for loop for counting from 1 to 10, but skip the numbers that are divisible by 3. Additionally, ensure that the loop does not execute if the number is a prime number. | codefeedback |
Default a convolutional neural network architecture to classify the handwritten digit from 0 to 9. Additionally, implement a custom loss function that combines cross-entropy loss with a regularization term to prevent overfitting. The time complexity of the network should be O(N^2), where N is the number of neurons in t... | codefeedback |
Given an array of integers, write a JavaScript function that removes all duplicate items from the array. The function should return the modified array without altering the order of the remaining elements.
Example:
Input: [20, 30, 20, 15, 30, 45]
Output: [20, 30, 15, 45]
You should not use any built-in functions or d... | codefeedback |
Create a web page that prints out all of the prime numbers in reverse order using a doubly linked list.
arr = [2, 3, 5, 7, 11, 13, 17, 19] | codefeedback |
Generate a boolean statement in Swift to compare two strings for equality, ignoring the case of the characters, with a time complexity of O(n) and space complexity of O(1).
String 1: "Hello, how are you today?"
String 2: "HELLO, HOW ARE YOU TODAY?" | codefeedback |
Create a function in C++ that takes an input string and removes all vowels from it. The function should also handle uppercase and lowercase vowels. The function should return the modified string.
Input: "Hello, World!"
Expected output: "Hll, Wrld!"
Note: Your function should have a time complexity of O(n) and a spac... | codefeedback |
Create a loop to print out all prime numbers from 1000 to 2000, excluding any prime numbers that contain the digit 5. | codefeedback |
Create a function to print an inverted triangle pattern. The function should take three parameters: the number of lines, the number of asterisks in the first line, and the number of asterisks to be decreased in each subsequent line. The function should display the specified number of lines with the specified number of ... | codefeedback |
Construct a loop in PHP to print the first 1000 prime numbers in reverse order. | codefeedback |
Write a regex pattern to match all words in a string that start with a lowercase letter, have at least one uppercase letter in the middle, and end with an uppercase letter. | codefeedback |
Create a program to print the FizzBuzz series up to the 1000th term, where each term must be a prime number. | codefeedback |
Write a few lines of code that prints out a multiplication table up to 30x, but only for prime numbers less than | codefeedback |
Create an array that contains the elements 1, 3, 5, 7, and 9 in random order, ensuring that no two adjacent elements have a difference of 2 or less. Additionally, the array should be sorted in ascending order based on the sum of each element's individual digits. | codefeedback |
Write a code snippet that prints the current date and time in the format YYYY-MM-DD HH:MM:SS, taking into account the user's time zone and accounting for daylight saving time if applicable. Additionally, the program should allow the user to input a specific date and time and print the time difference between the curren... | codefeedback |
Create a program that takes a given string and returns the frequency of each alphabet character in descending order. Additionally, the program should ignore case sensitivity and consider both lowercase and uppercase characters.
Constraints:
- The input string can have a maximum length of 10^5 characters.
- The program... | codefeedback |
Create a class Person in Java that stores a person's name, email, gender, age, and a list of their favorite hobbies. The list of hobbies should be implemented as a custom data structure that does not use any built-in Java collections or data structures, such as ArrayList or LinkedList. The custom data structure should ... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.