instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Create a program to output the squares of all numbers between 1 and 100, but exclude any numbers that are divisible by 3. Additionally, exclude any numbers that are divisible by 5. | codefeedback |
Design a responsive web page in HTML5 with a heading, a paragraph, a button, and a form that contains input fields for name, email, and a drop-down menu for selecting a country. Implement client-side validation for all input fields and display appropriate error messages if any field is left empty or if the email format... | codefeedback |
Create a SQL query to return every column from a table named 'books' where the title includes the word 'Ember' and the author's name starts with the letter 'J', but exclude any books published before the year 2000 and sort the results by the number of pages in descending order. | codefeedback |
How do you set up a YAML list with a specific size and initialize all the elements with a default value? Additionally, the default value must be a nested object that follows a specific schema. | codefeedback |
Given a list of dates, print the number of days in each month for each date in the list. Your solution should have a time complexity of O(n), where n is the number of dates in the list. | codefeedback |
Create a function to raise a given number to the Nth power. The number can be a decimal number and the exponent can be a negative number. The function should handle these cases as well. Additionally, the function should check if the given number is within a specific range, and if not, return an error message. The funct... | codefeedback |
Generate prime numbers between two given numbers where the sum of the digits of each prime number is a perfect square. The start and end numbers must be positive integers greater than 1.
Write a program that takes two inputs, start and end, and outputs a list of prime numbers between start and end, inclusive, that sa... | codefeedback |
Write a SQL query to select everyone from the table named 'users' with the first name equal to 'John' and the age greater than or equal to 25, but exclude anyone with the last name 'Doe'. | codefeedback |
Implement a function in C++ to return the inverse of a given square matrix.
Additional Requirements:
1. The input matrix must be invertible.
2. The function should handle matrices up to size 10x10.
3. The function should use a matrix inversion algorithm other than the Gauss-Jordan elimination method.
4. The function s... | codefeedback |
Split a list into two parts, where the first part contains odd numbers and the second part contains even numbers. The list should be split in such a way that the first part maintains the relative order of odd numbers and the second part maintains the relative order of even numbers. If there are no odd numbers or no eve... | codefeedback |
Edit the following JavaScript code to create an array of only the even numbers from the given array. The code should also sort the resulting array in descending order. The final array should only contain unique values and must not use any built-in array functions such as filter, map, or sort. The program must have a ti... | codefeedback |
Rewrite the code snippet in Python to find the second largest number across a list of integers, but without using the built-in `max()` or `sorted()` functions.
lst = [-1, 5, 10, 0, -9] | codefeedback |
Create a SQL query to find the number of employees with the same name as the given name 'John' and whose hire date is after '2010-01-01'. Additionally, sort the result in descending order based on the employees' salaries. | codefeedback |
Create a function to find the sum of the cubes of all prime numbers up to a certain number.
n = 1000000 | codefeedback |
Implement a text summarization program that uses the Gensim summarizer to summarize a given article. The program should allow the user to input specific keywords that they want to exclude from the summary. Furthermore, the summary should not exceed a maximum word limit specified by the user. The program should handle d... | codefeedback |
Create a regex expression in Python that finds all prime numbers from 1 to 100 inclusive. | codefeedback |
Design and implement a secure login page in HTML and CSS with the following requirements:
1. The login page should contain a username and password field.
2. The password field should be masked and have a minimum length of 8 characters.
3. Include a "forgot password" link that redirects to a password recovery page.
4. ... | codefeedback |
Write an algorithm in JavaScript for finding all common elements between two given integer arrays, while excluding any duplicates. The output should be sorted in ascending order. Both input arrays should not exceed a length of 10,000 elements. | codefeedback |
Write a code snippet to print a right aligned triangle of asterisks with a length of 10. The triangle should be printed upside down. Each row of the triangle should be indented by a number of spaces equal to its row number. | codefeedback |
Remove all duplicated characters from a string and return the modified string. If a character appears multiple times in a row, only the first occurrence should be kept. If the string is empty or contains no duplicated characters, return the original string.
For example:
Input: "abcabcabc"
Output: "abc"
Input: "hello"... | codefeedback |
How does a Naive Bayes classifier work and what are the steps involved in training it? Explain how it uses the training data to make predictions on new data. | codefeedback |
Create a class in Java for representing a Rectangle that stores length and width attributes and the following methods:
1. A method to calculate and return the area of the rectangle.
2. A method to calculate and return the perimeter of the rectangle.
3. A method to check and return whether the rectangle is a square or ... | codefeedback |
Write a Java code to take a string as input and return the number of unique words present in it. Consider that words are separated by one or more spaces and punctuation marks should be ignored.
Example:
Input: "Hello, how are you? How are you doing today?"
Output: 6 (Hello, how, are, you, doing, today)
Note:
- Words ... | codefeedback |
Implement a hash table using a dynamic array (instead of a fixed-size array) and handle collisions using separate chaining. Additionally, the hash function should be a custom implementation that takes into account the specific data types being stored in the hash table. | codefeedback |
Compare and contrast SQL and NoSQL databases, highlighting their advantages and disadvantages in terms of data modeling, scalability, performance, and querying capabilities. Additionally, discuss the use cases and industries where each type of database is most commonly used. Provide a piece of erroneous code in either ... | codefeedback |
Generate a multiplication table for a given number in JavaScript, but exclude the multiples of 3 and ensure that the table is printed in ascending order. The table should display the product of each number from 1 to n (inclusive) multiplied by the given number. n = 5; | codefeedback |
Construct a JavaScript program to find all the prime numbers within a range of numbers, where the range is provided as an array of two integers.
range = [10, 50]
Sample Output:
[11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
Note:
- You should handle cases where the range is empty or where the range only contains one n... | codefeedback |
Explain the concept of variable scope in programming and how it affects the behavior and performance of a program. Discuss the advantages and disadvantages of using global variables versus local variables, including their impact on memory usage and code maintainability. Provide code examples and scenarios to illustrate... | codefeedback |
What are the advantages and disadvantages of using an exception handler in programming? Provide a detailed explanation for each advantage and disadvantage mentioned. | codefeedback |
Build a function to convert an adjacency matrix into an adjacency list while also considering weighted edges. The function should take an additional matrix as input, representing the weights of each edge. The weights matrix should have the same dimensions as the adjacency matrix. Additionally, the function should handl... | codefeedback |
Explain the differences between a Dictionary and a List in Python and when to use each data structure. Provide code examples to support your explanation. Additionally, demonstrate the concept of polymorphism by implementing a function that can accept either a Dictionary or a List as an argument and perform a specific o... | codefeedback |
How can a programmer optimize a code that calculates the sum of an array using a divide-and-conquer algorithm, while ensuring that the code is also readable and maintainable? | codefeedback |
Write a function that takes in a list of integers and returns a tuple containing the minimum, maximum, and average values in the list. However, you are not allowed to use any built-in functions or methods such as min(), max(), sum(), len(), or sorted().
Example:
Input: [1, 2, 3, 4, 5]
Output: (1, 5, 3.0)
Time complex... | codefeedback |
Find the number of unique subsets of a given set, where each subset must contain at least one odd number. The given set may contain duplicates.
given_set = {1, 2, 2, 3, 4, 4, 5, 6, 7, 8, 9}
#Erroneous Code#
```
def count_unique_subsets(given_set):
subsets = []
for i in range(1, len(given_set) + 1):
for... | codefeedback |
Train a deep convolutional neural network (CNN) model in PyTorch to classify the given dataset of 50,000 images into 10 classes with at least 95% accuracy. The model should have a minimum of 8 layers, including convolutional, pooling, and fully connected layers. Additionally, the model should use both dropout and weigh... | codefeedback |
Parse the given XML document and calculate the total price of all the books in the bookstore. Additionally, for each book, calculate the average rating given by all the users who have reviewed the book. Assume that the XML document contains a list of books with their respective titles, prices, and user ratings. The XML... | codefeedback |
Create a query in SQL to find the record with id 2 and username "johndoe" from the table "users" and update the "email" column to "johndoe@example.com". | codefeedback |
Implement an algorithm in C++ for finding the kth largest prime number in an array of positive integers, where k is an input parameter. The array may contain both positive and negative integers. The function should return the kth largest prime number in the array.
Example:
Input: arr[] = {3, 7, 1, -2, 9, 5, 11, 8}, k... | codefeedback |
Create a while loop in Python to increment a counter by 1 until it reaches 100, but make sure to use a break statement inside the loop to exit the loop when the counter reaches a prime number. Additionally, implement a function to check if a number is prime and use this function within the loop. | codefeedback |
Implement a function to perform an in-place array rotation. The function should modify the original array `arr` and rotate it `rotation` number of times.
The input array `arr` will contain integers and have a length of at least 2.
The rotation can be either clockwise or counterclockwise, and the function should be ab... | codefeedback |
Write a shell script to monitor the usages of CPU and RAM, and notify the user when the CPU usage exceeds 90% or the RAM usage exceeds 80%. Additionally, the script should log the usage data to a file every 10 seconds. However, the script should now be able to handle multiple users simultaneously and provide individual... | codefeedback |
Build a quickly-sortable tree from a given array.
Array = [3, 8, 4, 5, 2, 10, 7]
Additional Instructions:
1. Implement the sorting algorithm yourself instead of using built-in sort functions.
2. The tree should be built in a way that allows for efficient insertion and retrieval of elements.
3. The tree should be sorte... | codefeedback |
Identify the data structure most suitable for storing 100,000 unique integers in ascending order. Additionally, the data structure should support fast lookup, insertion, and deletion operations with a time complexity of O(log n) or better. The implementation should use only a fixed amount of memory, not exceeding 1 MB. | codefeedback |
Write a function that takes two strings and determines if the first string is one character away from the second string. The function should handle case sensitivity and whitespace. Additionally, the function should return False if the two strings have a difference in length greater than 1. The function should have a ti... | codefeedback |
Write a function that returns the number of times an element appears in a sorted array. The function should only use a single loop and have a time complexity of O(log n), where n is the size of the array. The array will contain at most 10^9 elements and the element to search for will be a positive integer between 1 and... | codefeedback |
Design a class for a grocery store inventory management system that supports the following functionalities:
1. Add a new product to the inventory. The product should also have a category associated with it.
2. Remove a product from the inventory. The removal should be based on the category of the product.
3. Update the... | codefeedback |
Write a C++ function that takes a string as input and removes all special characters from it. Special characters include any non-alphanumeric characters except whitespace. The function should modify the original string and return it. Additionally, the function should also count the number of occurrences of each alphabe... | codefeedback |
Explain the process of linear search, ensuring that the search is case-sensitive and the input array must be sorted in ascending order. Also, provide the algorithm for implementing linear search in code and explain its time complexity. | codefeedback |
Create a Regex in JavaScript to extract all words of length 8 or more that start with a vowel and end with a consonant from a sentence. Additionally, the regex should ignore any words that contain a number or special character.
Sentence = "This is a sample sentence with some words of length 8 or more, such as 'progra... | codefeedback |
Write a loop in Java to add all elements of a given array and return the sum.
However, you are not allowed to use the addition operator (+) or the multiplication operator (*) in your code.
You can only use bitwise operators, assignment operators, and logical operators.
The array will contain positive integers only. ... | codefeedback |
Given two strings, find the minimum number of operations required to convert one string to the other using the following operations:
- Insert a character
- Delete a character
- Replace a character
String 1 = "kitten"
String 2 = "sitting"
Example:
Input: "kitten", "sitting"
Output: 3
Explanation:
To convert "kitten"... | codefeedback |
Create a function that takes an array of integers and prints out their product. The function should also handle cases where the array contains negative integers. The function should have a time complexity of O(n) and a space complexity of O(1).
Example:
array = [1, -2, 3, 4, -5]
Expected output:
The product of the ar... | codefeedback |
Suppose a set of n positive integers and write a program to calculate the kth smallest element in the set, where k is a positive integer and k <= n. Your program should also ensure that the kth smallest element is unique in the set.
int[] numbers = {3,7,5,14,15,17};
int k = 3;
The program should find and output the ... | codefeedback |
Write a function to traverse a binary search tree using depth-first search algorithm in Java, without using recursion. Additionally, implement a method to calculate the sum of all the nodes in the tree and return the result.
You may assume that the binary search tree only contains positive integers.
Note: Depth-first... | codefeedback |
Write a code to generate a random password using the random library of Python. The password should satisfy the following requirements:
- The length of the password should be between 8 and 12 characters.
- The password should contain at least one uppercase letter, one lowercase letter, one digit, and one special charact... | codefeedback |
Construct an algorithm to detect a cycle in a linked list, but you are not allowed to use additional space. Additionally, you are not allowed to modify the linked list in any way. | codefeedback |
Write a function to determine the largest prime number in a sorted array of integers. The function should have a time complexity of O(log n) and a space complexity of O(1).
array = [1, 3, 4, 6, 8] | codefeedback |
Implement a web application that allows users to create and manage a personal to-do list. The application should have the following functionalities:
1. Users should be able to add new tasks to their to-do list.
2. Users should be able to mark tasks as completed.
3. Users should be able to delete tasks from their to-do ... | codefeedback |
Create a new vector of size N filled with random integers between 1 and M (inclusive), where N and M are inputs provided by the user. The size of the vector should be at least 10^6 and the range of random integers should be at least 10^4. The solution should have a time complexity of O(N) and a space complexity of O(N)... | codefeedback |
Convert a string to its corresponding integer value, taking into account negative numbers, leading/trailing whitespace, and hexadecimal representation.
String: "- 0xFF " | codefeedback |
Write a for loop for printing the first 10 powers of 3, starting from 3^0, but you are not allowed to use the exponentiation operator or any built-in function that calculates powers. | codefeedback |
Remove all duplicates from an array of strings while preserving the order of the elements. Additionally, the resulting array should only contain strings that are palindromes.
Input: ["racecar", "apple", "level", "banana", "deed", "madam", "dog", "dad"]
Output: ["racecar", "level", "deed", "madam"] | codefeedback |
Create a tower of stars made up of n lines of increasing star lengths, where n is an odd number greater than or equal to 10. Each line must contain an odd number of stars. | codefeedback |
Given a 1GB RAM, determine the maximum number of 256-bit numbers that can fit while considering the size overhead of the programming language's data structures and memory allocation. Take into account any potential alignment or padding requirements for the 256-bit numbers in memory. You must also consider the impact of... | codefeedback |
Build a program to print the frequency of characters in an input string, considering only alphabets (a-z, A-Z). The input string may contain spaces, special characters, and numbers.
Example input_string: "abc@!123 ABCabc"
The program should ignore spaces, special characters, and numbers while calculating the frequency... | codefeedback |
Write a function for removing duplicate values from an array, without using any built-in methods or data structures (such as sets or dictionaries) to store unique values. Additionally, the function should be able to handle arrays containing non-integer values, including strings and objects. | codefeedback |
Write a function that takes in a positive integer as input and returns True if the number is a prime number and False otherwise. The function should have a time complexity of O(sqrt(n)), where n is the input number.
Example:
Input: 17
Output: True | codefeedback |
Implement a Turing machine in a programming language of your choice. The Turing machine should be able to simulate a specific problem, such as finding the factorial of a given number or checking the validity of a mathematical expression. Write a comprehensive set of unit tests to verify the correctness of the Turing ma... | codefeedback |
Create a function that takes in three parameters: the class name of the elements to change, the new color to change them to, and the duration of the color transition animation in milliseconds. The function should change the background color of all elements with the given class name to the specified new color over the s... | codefeedback |
Create a React component for displaying a list of items with name, description, and price fields. The list should support pagination, with each page showing a maximum of 10 items. Add a button to each item that, when clicked, removes the item from the list. Additionally, implement a search functionality that allows use... | codefeedback |
Write a function in Java to delete all numbers from an array which are divisible by three and are even, and then sort the remaining numbers in ascending order. Additionally, you need to find the sum of all the remaining numbers and return it.
Additional requirement: The function should have a time complexity of O(nlog... | codefeedback |
Implement the Mahalanobis distance formula using a def function in Python, without using any built-in functions or libraries for matrix calculations. The Mahalanobis distance formula calculates the distance between a point and a distribution by taking into account the covariance between variables.
The function should ... | codefeedback |
Create a database table for a social media application that includes the following fields: user_id (unique identifier for each user), username (must be at least 8 characters long and can contain only lowercase letters and numbers), email (must be a valid email format), password (must be at least 12 characters long and ... | codefeedback |
Write a program that takes in a list of integers and returns the smallest positive integer that is not present in the list. The program should also handle the case where the input list is empty.
Additional constraints:
- The input list can contain up to 1,000,000 integers.
- The input list can contain positive and neg... | codefeedback |
Acquire the necessary data to apply linear regression on the following problem statement
Predict the average property value in a particular city given the population density, housing costs, average income, the crime rate, and the percentage of residents with a college degree. | codefeedback |
Create a 2D array with n columns and m rows and fill it with random numbers. Additionally, write a function that calculates the average of each row in the array and returns the row with the highest average value. Print out the row number and its corresponding average value.
Rows: 100, Columns: 100
Restrictions:
- Th... | codefeedback |
Translate the following sentiment analysis model written in Python to JavaScript. Additionally, add a piece of erroneous code as a reference to increase misdirection.
model = tf.keras.models.Sequential([
tf.keras.layers.Dense(128, activation='relu', input_shape=(train_data.shape[1],)),
tf.keras.layers.Dense(64, ac... | codefeedback |
Write a MySQL query to join 4 tables and apply a complex filtering condition.
Table1: users
ID | Name | Email
Table2: orders
OrderID | UserID | OrderDate
Table3: products
ProductID | ProductName | Price
Table4: categories
CategoryID | CategoryName
The query should retrieve the following information:
- User's name ... | codefeedback |
Given a text, find all words that contain the string "ed" in the text and start with a vowel. Output the total count of these words.
Example Input:
"The editor edited the document. I am interested in learning more."
Example Output:
Total count of words that contain the string "ed" and start with a vowel: 2
Explanat... | codefeedback |
Given an array of strings, generate an object with the strings as keys and the length of each string as values. The generated object should only include strings that have a length greater than or equal to 3 characters. Additionally, the generated object should not include any strings that contain special characters or ... | codefeedback |
Design a program to detect an infinite loop in a given program, without using any loops or recursion. Additionally, provide an erroneous code snippet that may initially misdirect the programmer. | codefeedback |
Create a Tkinter window with a label that says “Hello World!” and a button that, when clicked, changes the label text to a random prime number between 1 and 100. | codefeedback |
Write an SQL query to select the "name", "salary", and "department" columns of all employees who have a salary greater than the average salary of their respective department. Additionally, order the results in descending order of salary. Also, include only those employees whose department has more than 5 employees.
Ta... | codefeedback |
Design an object-oriented application that provides a way for users to store and access their banking records. The application should include the following functionality: creating accounts, making deposits and withdrawals, transferring funds between accounts, and generating account statements.
Additional requirements:... | codefeedback |
Create a scalable Django application to serve an API endpoint.
The API endpoint should take an ID and return a user's name, age, and a list of their previous addresses.
The user's name and age should be stored in a database table called "users". Each user should have a unique ID, name, and age. The user's name should ... | codefeedback |
Design a data structure for a deck of cards that supports the following operations:
1. Shuffle: Randomly rearranges the order of the cards in the deck.
2. Draw: Removes and returns the top card from the deck.
3. Insert: Inserts a new card at a specific position in the deck.
4. Remove: Removes a specific card from the d... | codefeedback |
Create a class that represents a banking system in Python. The class should have the following attributes and methods:
Attributes:
- account_number (a randomly generated alphanumeric string of length 16)
- account_balance (a floating-point number representing the current balance of the account)
- transaction_history (... | codefeedback |
Design an algorithm to help a user navigate through a maze. The maze is represented as a two-dimensional grid where each cell can be either empty or blocked. The user starts at the top-left cell and must reach the bottom-right cell.
Your algorithm should find a path from the start to the destination cell, if it exists... | codefeedback |
What is the value of "c" after the code is executed if "a" and "b" are both positive integers and "c" should be rounded to the nearest whole number?
a = 10, b = 20, c = a * b + a^b
Note: The calculation for "c" now involves multiplication and exponentiation in addition to addition, which increases the complexity of ... | codefeedback |
Sort the list in ascending order of the sum of the absolute values of the elements in each tuple. If two tuples have the same sum, sort them based on the second element in descending order.
list = [(-5, 2), (1, 0), (1, 3), (3, 4), (-3, -9), (-10, -2)]
# Solution
def sort_list(lst):
lst.sort(key=lambda x: (sum(abs... | codefeedback |
Consider the following scenario in a company where employees can have multiple roles. Each role has a different salary associated with it. Write an SQL query to calculate the average salary for each role in each department in the company. | codefeedback |
Create a web application using Flask, which provides a search form that can handle a large dataset of over 1 million records efficiently and returns results in real-time. The search functionality should support fuzzy search, where users can find results even if they have typos or minor errors in their search query. Add... | codefeedback |
Create a JavaScript program that simulates a game of blackjack between a player and a computer dealer. The program should allow the player to make decisions such as hitting or standing, and should also handle the dealer's actions automatically.
The program should have the following functionalities:
1. Allow the playe... | codefeedback |
Using the input "dictionary" of type dict, write code to print out the frequency of each word in the dictionary. Additionally, print out the words in descending order of their frequency. If two or more words have the same frequency, sort them alphabetically. The frequency of each word should be represented as a percent... | codefeedback |
Design a memory efficient algorithm for a given problem.
Given a list of integers, find the average of all the elements.
The algorithm must have a time complexity of O(n) and use only a constant amount of extra space.
Additionally, the algorithm must handle negative numbers and floating-point numbers in the list. | codefeedback |
Create a function that takes two strings as parameters, compares them, and returns 0 if they are equal, 1 if the first string is greater (based on lexicographic order), and -1 if the second string is greater.
In addition, you need to handle the following edge cases:
1. If either of the strings is empty, return -2.
2... | codefeedback |
Create a function that takes in an array of integers and returns a new array with only the prime numbers from the original array. The prime numbers should be sorted in ascending order.
Example:
Input: [3, 2, 4, 5, 8]
Output: [2, 3, 5]
Please note that your code should have a time complexity of O(n * sqrt(m)), where n... | codefeedback |
Write a program that implements a binary search algorithm to find the index of a given target value in a sorted array. The program should use the Test-Driven Development (TDD) methodology, where you write the test cases first and then implement the code to pass those tests. The binary search algorithm should have a tim... | codefeedback |
Write a SQL query that outputs the names and ages of all the students in a given table who have achieved a grade higher than 90, sorted in descending order of their age and limited to the top 5 oldest students. | codefeedback |
Write a function to calculate the cosine similarity between two given sentences. The function should take into account stop words, perform stemming, and lemmatization before calculating the cosine similarity. The sentences should be preprocessed by removing punctuation, converting to lowercase, and removing any duplica... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.