instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
You are given a list of positive and negative integers. Find the maximum sum of any contiguous subarray in the list. The length of the list will not exceed 10^6.
Additional Constraints:
- Your algorithm should have a time complexity of O(n), where n is the length of the list.
- The maximum space complexity allowed is ... | codefeedback |
What is this coding question asking you to do?
Write a Python function to check whether a number is a perfect prime or not. A perfect prime is a prime number that is also equal to the sum of its proper divisors (excluding itself).
#New Test#
Write a Python function to check whether a number is a perfect prime or not. ... | codefeedback |
Remove all elements with the value "Carrots" from the given list and return the modified list. If there are multiple occurrences of "Carrots", remove all except for the first occurrence. The input list can contain any number of elements. If the input list is empty, return an empty list.
Sample Input: ["Apples", "Orang... | codefeedback |
Create an SQL query to find the number of employees whose age is between 30 and 40, excluding those whose age is divisible by 5 and whose salary is above $50,000. | codefeedback |
Create a JavaScript object with key-value pairs representing names and ages. However, the names should be limited to a maximum of 5 characters and the ages should be between 21 and 35 (inclusive). Additionally, the names should be unique within the object, and the ages should be sorted in ascending order when the objec... | codefeedback |
List out all the sorting algorithms supported in Python, excluding built-in sorting functions, and provide a piece of erroneous code showcasing the usage of one of the algorithms. Your code should handle edge cases and display appropriate error messages. | codefeedback |
Explain the advantages and disadvantages of using the following linear regression algorithm in Python.
Linear Regression using Stochastic Gradient Descent
Provide an example of a dataset where the use of Stochastic Gradient Descent for linear regression may not be suitable and explain why.
Additionally, provide the c... | codefeedback |
Find all the possible permutations in a string without using any built-in functions, where the input string can contain duplicate characters. However, now the input string can also contain special characters such as '@', '$', and '&'.
string = "ABA@&" | codefeedback |
Create a function that removes duplicates from an array and returns an array of the unique values. The function should only use O(1) additional space and have a time complexity of O(n), where n is the length of the input array. The input array can contain integers, floating-point numbers, strings, and nested arrays. Th... | codefeedback |
Implement a function to calculate the greatest common divisor of two numbers.
Inputs: Two positive integers, A and B, where 1 <= A, B <= 10^9
The function should return the greatest common divisor (GCD) of A and B.
Note:
- The GCD of two numbers is the largest positive integer that divides both numbers without leavin... | codefeedback |
Design an abstract employee class with following members. The employee should have a minimum of 4 attributes and 3 methods. Additionally, each attribute should have a data type of your choice and each method should have a return type of your choice.
Furthermore, one of the attributes should be a static variable that k... | codefeedback |
In HTML and JavaScript, write a code to create a registration form that includes fields for the user's first name, last name, email address, and password. Additionally, add a confirmation field for the user to re-enter their password to ensure accuracy. Implement client-side validation to check that the password meets ... | codefeedback |
Using the list of strings, create a new list without any vowels. Additionally, remove any duplicates from the final list and sort it in descending order based on the length of the strings. Finally, only include strings that contain at least one uppercase letter and one lowercase letter.
strings = ['Apple', 'Ball', 'c... | codefeedback |
Write a JavaScript function to find all unique words in a string, ignoring any common stop words such as "the", "and", "or", "is".
Additionally, implement the following features:
1. The function should be case-insensitive, meaning it should consider "The" and "the" as the same word.
2. The function should remove any p... | codefeedback |
Write a CSS rule to hide all elements with class "hidden" that are nested within a div element with class "container", but only if the div element has a sibling with class "wrapper". | codefeedback |
Implement a variation of the cocktail sort algorithm to sort a given array of 16 elements in ascending order. Additionally, keep track of the number of swaps performed during the sorting process and print the final sorted array after each iteration. | codefeedback |
Create a class named "Car" to store information about a car's make, model, year, and mileage. Implement a method called "update_mileage" that takes in a parameter for the number of miles driven and updates the car's mileage accordingly.
Additionally, add a method called "get_average_mileage" that calculates and retur... | codefeedback |
Create a function named "parse_urls" which takes a single string parameter and returns a dictionary of queries from the URL. The URL can contain multiple query parameters separated by "&". Each query parameter is represented by a key-value pair, with the key and value separated by an equals sign ("="). The value can be... | codefeedback |
Create a JavaScript function to take an array of numbers and return the sum of all its elements, but without using any built-in array methods such as reduce, map, or forEach. Additionally, you are not allowed to use the addition operator (+) or any arithmetic operators (+, -, *, /) to perform addition. The time complex... | codefeedback |
Create a Java program to take an integer input from the user within the range of 1 to 20 (inclusive) and print its factorial. The program should handle the case when the input is out of range by displaying an appropriate error message. Additionally, implement the factorial calculation using recursion instead of iterati... | codefeedback |
Encrypt a given string using a Vigenère cipher with a randomly generated key phrase.
String: "Hello World" | codefeedback |
Create a Java class to represent a new type of vehicle called hovercar, which can only be powered by a specific type of energy called "ion fuel" and has a maximum speed of 500 km/h. Additionally, the hovercar should have the ability to levitate at a certain height above the ground, with the height being adjustable by t... | codefeedback |
Define a Java annotation that can be used to annotate a method and specify the maximum number of times the method can be called in a given time interval. Additionally, implement a mechanism to automatically track and enforce the limit, so that if the method is called more times than allowed within the specified interva... | codefeedback |
How are dictionaries implemented in Python and what is the average time complexity of common operations such as insertion, deletion, and retrieval? Additionally, explain the trade-offs between using a dictionary and a list in terms of memory usage and time complexity. | codefeedback |
Construct a 4 level hierarchical tree data structure in PHP. The tree must be balanced and each level must have a maximum of 10 nodes. Additionally, each node must have a unique identifier and a randomly generated value between 1 and 100. The tree must also support the following operations:
1. Insertion of a new node a... | codefeedback |
Create a regular expression to select all words starting with 'a' that are followed by either a vowel or the letter 'r' and are not followed by the letter 's'. | codefeedback |
Train a machine learning algorithm to predict whether a student will pass or fail an exam based on a given dataset. The dataset contains information about students' results in previous exams, as well as additional features such as their study hours, attendance, and socioeconomic background.
Additional requirements:
1.... | codefeedback |
Write a function in C that takes an array of float numbers as input and returns the sum of the square roots of the numbers. The function should handle arrays with up to 1000 elements and ensure that all input numbers are positive. If any negative numbers are found in the array, the function should return -1. Additional... | codefeedback |
Create a SQL statement to select the five highest-paid employees who have been with the company for at least five years, and have received at least one promotion during their employment. | codefeedback |
Write a Java program to generate a schedule for students with a given set of available IDs and a specified maximum number of courses per student. Each course has a unique ID, title, instructor, and meeting time. The program should allow students to select their desired courses from a list of available courses and creat... | codefeedback |
Find the product of all prime numbers less than or equal to n, where n is the largest number in the given list. If there are no prime numbers in the list, return 0. Implement this in JavaScript.
List: [8, 3, 6, 7, 12, 5, 15, 11] | codefeedback |
Write a function to parse a string and return a dictionary where each character in the string is mapped to its frequency. The function should also exclude any characters that are not letters or numbers. The string should be case sensitive and the function should return the dictionary in descending order of frequency. A... | codefeedback |
Find all the prime numbers in a Python list using list comprehension.
list = [2, 3, 4, 5, 6, 7, 8, 9]
# Erroneous code as reference
# This code checks for divisibility of each number in the list by all numbers from 2 to the number itself.
# However, it fails to exclude the number itself and 1 as factors, resulting in ... | codefeedback |
Write a SQL query to find information about books in a library, including the total number of copies available for each book, the average rating of each book, and the number of times each book has been borrowed. Also, include only books that have been published within the last year and have an average rating above 4.0.... | codefeedback |
Create a dynamic and interactive data visualization in Python using the given dataset. The visualization should include the following:
1. Use a choropleth map to display the latest coronavirus cases per US state. Each state should be color-coded based on the number of cases, with a legend indicating the range of value... | codefeedback |
Escalate privileges in a Windows system using PowerShell by creating a script that not only grants administrative privileges but also performs a series of automated tasks, such as creating a new user account with a randomized password, modifying critical system files, disabling certain security features, and ensuring a... | codefeedback |
Write a JavaScript program to compute the value obtained by concatenating the three given strings, with the following added conditions:
1. If any of the strings is null or empty, the program should throw an error with a custom message.
2. If the concatenated string contains any special characters or numbers, the progra... | codefeedback |
Write Python code to store odd numbers from the given list in a separate list. Additionally, the code should also remove any duplicate odd numbers from the new list. The code should not use any built-in functions or libraries to remove duplicates from the list, and it should also be implemented in a way that has a time... | codefeedback |
Evaluate an expression written in reverse Polish notation, where the operands can be any positive or negative integer and the operators can be addition, subtraction, multiplication, and division. The expression may contain parentheses as well. The expression may also include unary operators such as negation. The expres... | codefeedback |
Write a SQL statement to update the 'salary' of all employees in the 'sales' department by 10%, but only for those employees whose 'salary' is above the average salary of all employees in the 'sales' department. Additionally, ensure that the update statement is atomic and does not result in any concurrency issues when ... | codefeedback |
Explain the concept of shallow copy and deep copy in Java. Provide examples to illustrate the differences between the two techniques and discuss when each one should be used. Additionally, analyze the time and space complexity of each technique and suggest improvements or alternative approaches to optimize the copying ... | codefeedback |
Normalize a dataset of strings and count the occurrences of each unique normalized string.
Input:
- A dataset of strings. Each string represents a location in the format "City, State/Province".
Output:
- A dataset of normalized strings, where each string is in the format "City, State/Province" with no leading or tra... | codefeedback |
Rewrite the given Python code snippet using nested list comprehensions and an additional condition. The additional condition is that the sum of the sublist should be a prime number.
even_list = [x for sublist in my_list for x in sublist if x % 2 == 0 and sum(sublist) > 1 and all(sum(sublist) % i != 0 for i in range(2... | codefeedback |
Construct a SQL query to count the number of employees with the same 'state' value in the employees table, but also include the number of employees with a different 'state' value in the result. Additionally, only consider employees who have a hire date within the last 3 months and whose salary is above the average sala... | codefeedback |
Edit the following HTML code to add an attribute and its value, while ensuring that the attribute is unique and does not already exist in the code. Additionally, create a JavaScript function that will alert the user when the div element is clicked.
<div class="container">
<h1>Welcome!</h1>
</div>
<script>
fun... | codefeedback |
Modify the given code snippet to add a new entry in the users table of a MySQL database. The new entry should include the user's name, email, age, and a randomly generated unique identifier for each user. Ensure that the email address is unique and the age is a positive integer. Additionally, implement a validation mec... | codefeedback |
Write a recursive function in Python that calculates the factorial of a given positive integer. The function should have a time complexity of O(n), where n is the given positive integer. Additionally, the function should not use any loops or helper functions. | codefeedback |
What code should be written to generate a random string with 15 characters in JavaScript, ensuring that no character is repeated within the string? Additionally, the code should have a time complexity of O(n) and should not use any built-in JavaScript functions for generating random characters or shuffling arrays. | codefeedback |
Given an unsorted array of integers, write a program to find the kth largest element. The value of k will be provided as input to the program. The array will contain at most 10^5 elements and all elements will be unique positive integers ranging from 1 to 10^9.
For example, given the array [3, 10, 2, 6, 4] and k = 2, ... | codefeedback |
Assign a value to `name` based on a complex condition that involves at least 5 variables and 3 logical operators. The condition should include both logical and comparison operators. The complexity should be at least O(n^2), where n is the number of variables involved in the condition. Additionally, the condition should... | codefeedback |
Write a Java program that generates 5 random numbers between 1 and 100, inclusive, and stores them in an array. The program should then sort the array in ascending order and display the sorted numbers. Additionally, the program should ensure that no duplicate numbers are generated and display an error message if duplic... | codefeedback |
Write a callback function that takes in three arguments: a string, a number, and a boolean flag. This callback should be able to store the input and emit it when triggered. Additionally, modify the function signature to indicate that the callback can only be triggered once and that the flag must be set to true before t... | codefeedback |
Suggest a few input parameters for a Machine Learning model that will be used to classify handwritten digits, considering that the model should achieve an accuracy of at least 95% on a test dataset of 10,000 images, while also being trained within a time constraint of 10 minutes on a CPU with 4 cores and 8 GB of RAM. | codefeedback |
Extract the phone numbers from a string of text. The phone numbers should be in the format (XXX) XXX-XXXX. The string may contain multiple phone numbers and other non-numeric characters. Return the phone numbers in a list in the order they appear in the string. The solution should handle international phone numbers in ... | codefeedback |
Create a C# method to find the third common element in two arrays, but the method should have a time complexity of O(n), where n is the total number of elements in both arrays. | codefeedback |
Construct a nested for loop to access each element of the given 2D array. However, instead of accessing each element sequentially, you need to access the elements in a zigzag pattern. | codefeedback |
Implement an in-order traversal of a binary search tree in Python, without using recursion. Additionally, the implementation should be able to handle cases where the binary search tree contains duplicate values, and should visit each node with the same value in the order in which they were inserted into the tree. | codefeedback |
Write a C code snippet to check if an input number is prime or not. The number is 17. Your code should not use any built-in prime-checking functions or libraries.
In addition to checking if the number is divisible by any numbers less than itself, the code should also check if the number is divisible by any prime numbe... | codefeedback |
Create a shell script that prints the Fibonacci sequence up to a given number, n. The script should accept n as a command line argument and output the Fibonacci sequence up to the nth term.
Requirements:
- The script should have a time complexity of O(n).
- The script should not use any external libraries or commands ... | codefeedback |
Create a function to generate the weight of a given sequence of DNA based on the following rules:
1. Each nucleotide in the DNA sequence has a specific weight assigned to it: A = 1, C = 2, G = 3, T = 4.
2. The weight of the DNA sequence is calculated as the sum of the weights of each nucleotide in the sequence.
3. If a... | codefeedback |
Find the minimum number of coins required to make a given amount using a dynamic programming approach.
You are given a list of available coin denominations, and you can use any number of coins of each denomination.
Write a function `minCoins(amount: int, coins: List[int]) -> int` that returns the minimum number of coi... | codefeedback |
Construct a JSON object with the given parameters and return the object. However, the name and age parameters should be encrypted before being included in the JSON object. The encryption algorithm should be a custom algorithm that you need to design. The encrypted values should still be valid strings that can be decryp... | codefeedback |
Create a class in Python named 'Rectangle' which can compute the area and perimeter of a rectangle. The class should include the following methods:
1. A method named 'get_dimensions' that takes the width and height of the rectangle as inputs and stores them as attributes of the class.
2. A method named 'get_area' tha... | codefeedback |
Design an algorithm for finding the median value of a linked list. Your algorithm should have a time complexity of O(nlogn) and space complexity of O(1). The linked list may contain duplicate values and it should be handled appropriately in your algorithm. | codefeedback |
Design an algorithm to check if a string contains a given substring in reverse order, taking into account both uppercase and lowercase characters. | codefeedback |
Write a function that exchanges the first and last elements of a list. The function should also remove any duplicate elements from the list, while maintaining the order of the remaining elements.
Additional requirements:
1. The function should have a time complexity of O(n), where n is the length of the list.
2. The f... | codefeedback |
Create an algorithm to check if a binary tree is univalued, where the nodes in the tree store integers and the univalued property means that all nodes in the tree have the same integer value. Additionally, the algorithm should find and return the number of distinct values present in the tree.
You may assume that the ... | codefeedback |
Generate an algorithm to multiply two numbers without using multiplication operator. The algorithm should have a time complexity of O(log N), where N is the larger of the two numbers. Additionally, the algorithm should have a space complexity of O(1), i.e., it should not use any additional memory apart from the variabl... | codefeedback |
Reverse a given list without using any predefined functions. 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 loops or recursion in your solution. | codefeedback |
Suppose we have a dictionary with keys (1,2,3,4,5,6,7,8,9,10). Create a function that returns the values of the dictionary in descending order of their lengths.
d = {1: "one", 2: "two", 3: "three", 4: "four", 5: "five", 6: "six", 7: "seven", 8: "eight", 9: "nine", 10: "ten"}
Example:
Input: {1: "one", 2: "two", 3: "t... | codefeedback |
Fix the following Python code to create a dictionary where the keys are prime numbers between 1 and 100 and the values are lists containing the corresponding key and its squared value. | codefeedback |
Parse a JSON response into a Python dictionary, ensuring that the "name" value is a string and the "age" value is an integer. The "name" value should be at least 3 characters long and should contain only alphabetic characters. The "age" value should be between 18 and 99 (inclusive) and should be a positive integer. Add... | codefeedback |
Given an array of integers, multiply each element by the smallest prime number greater than 3 and return the new array. Additionally, if any element in the array is divisible by the smallest prime number greater than 3, replace that element with the next prime number greater than 3 before multiplying. | codefeedback |
In the given string, split the words and remove empty strings. Each word should contain at least two characters. Additionally, remove any leading or trailing whitespace from each word. Lastly, sort the words in descending order based on their length. string = " Hello World " | codefeedback |
Remove the duplicates from the list without using built-in methods. However, you are only allowed to use a single loop. The original list is not allowed to be modified, and the resulting list should maintain the original order of elements. The time complexity of your solution should be O(n) and the space complexity sho... | codefeedback |
Write a query to sort a table data by their names in reverse alphabetical order, while ignoring trailing articles such as "The", "A", and "An". | codefeedback |
Please write a code to convert a given date string into a timestamp. The input date string will always be in the format "YYYY-MM-DD HH:MM:SS".
Your code should also handle time zones and daylight saving time. You can assume that the input date string will always be in the UTC time zone.
You are not allowed to use an... | codefeedback |
Write a JavaScript function that takes in an array of integers and returns the sum of all the prime numbers in the array. However, you are not allowed to use any built-in JavaScript functions to check if a number is prime. You must implement your own algorithm to determine if a number is prime or not. | codefeedback |
Write a function that takes in four parameters: a number, the current base of the number, the target base to convert the number to, and a boolean flag indicating whether to perform a rounded conversion. The function should return the number converted to the target base.
If the flag is set to true, the function should ... | codefeedback |
Create a dictionary containing the characters from the given string as keys and their frequency in the string as values. The string can contain any printable ASCII characters, including upper and lower case letters, numbers, and special characters. The dictionary should be sorted in descending order based on the freque... | codefeedback |
Rewrite the given test as follows:
#Rewritten Test#
Design a function that generates an array of n-dimensional vectors, where each vector must have at least one positive and one negative element. Additionally, the function should ensure that the sum of all elements in each vector is equal to a given target value. The ... | codefeedback |
Write a code to generate a random 10 digit phone number that starts with a specific area code and has the following restrictions:
- The second digit must be odd.
- The third digit must be a prime number.
- The fourth and fifth digits must be consecutive numbers.
- The sixth and seventh digits must be the same.
- The ei... | codefeedback |
Parse the given string and return a dictionary with the keys and corresponding values. The string contains information about multiple people. Each person's information starts with "name", followed by their name, "age", followed by their age, and "occupation", followed by their occupation. The information for each perso... | codefeedback |
Given a binary tree data structure, write a program to find the maximum depth of the tree. Your solution should have a time complexity of O(n), where n is the number of nodes in the tree. Additionally, you should not use any built-in libraries or data structures to solve this problem. The nodes in the tree will contain... | codefeedback |
Convert a sentence into a list of words using the provided function, but exclude any words that start with a vowel and contain more than three letters. Additionally, sort the resulting list in alphabetical order. | codefeedback |
How would you reverse a doubly linked list without using any additional data structures, in quadratic time complexity and constant space complexity? | codefeedback |
Create a loop that prints out the prime numbers from the given list. However, before printing each number, check if it is an even number. If it is an even number, skip it and move on to the next number. After printing all the prime numbers, also print the total count of prime numbers that are even.
lst = [1, 2, 3, 4, ... | codefeedback |
Generate a random PIN of 12 characters that must satisfy the following conditions:
1. At least two characters must be lowercase letters.
2. At least two characters must be uppercase letters.
3. At least two characters must be digits.
4. At least two characters must be special characters (!@#$%^&*).
Additionally, the g... | codefeedback |
Given a dictionary of words and a set of characters, how would you find the longest word which can be constructed from the given set of characters? Additionally, the characters in the set can be used multiple times to construct the word. The solution should have a time complexity of O(n), where n is the length of the d... | codefeedback |
Generate a list of length n containing all numbers from 1 to n, but without using any built-in functions or libraries. The time complexity should be O(n) and the space complexity should be O(1). Additionally, you are not allowed to use any loops or recursion in your solution. | codefeedback |
Create a function that checks whether a given number is a prime number using the Sieve of Eratosthenes algorithm. The function should also return the smallest prime factor of the number if it is not a prime number. The function should efficiently handle numbers up to 10^9 and should be optimized for performance.
You s... | codefeedback |
Using an existing function, update the given array of positive integers to contain elements which are the square of each original element. The updated array should also exclude any numbers that are divisible by 3. The function should return the sum of all the remaining elements in the updated array. You are not allowed... | codefeedback |
Answer this logic programming question: What is the transitive closure of the binary relation "less than or equal to" on the set of integers?
Erroneous code reference:
What would be the output of the following code snippet?
```python
def transitive_closure_less_than(nums):
closure = set()
for i in nums:
... | codefeedback |
Create a class in Python called Math that can calculate the average of two numbers.
The class should include a method called "calculate_sum" that calculates the sum of two numbers instead of the average.
Additionally, the class should have a method called "calculate_product" that calculates the product of two number... | codefeedback |
Print all permutations of an input array in lexicographically sorted order, without using any additional memory space. The solution should have a time complexity of O(n!), where n is the length of the input array.
array = [1,2,3] | codefeedback |
Create an R function that plots a histogram of a given data set, ensuring that the histogram has at least 10 bins and the x-axis is labeled with the range of values in the data set. Additionally, the histogram should have a title indicating the number of data points included in the plot. Your function should also inclu... | codefeedback |
Write a Python function that takes a list of integers as input and returns a list containing only the prime numbers from the input list. If the input is not a list of integers, the function should raise a ValueError. The time complexity of the function should be less than or equal to O(n^2), where n is the length of th... | codefeedback |
Implement a class that simulates a bank account. The class should have the following properties and methods:
1. Properties:
- balance (an instance variable) - stores the current balance of the account.
- account_number (a static variable) - stores a unique account number for each account.
2. Methods:
- depos... | codefeedback |
Create a Python function that takes in a list of positive integers and returns the length of the longest increasing subsequence. An increasing subsequence is a sequence of elements where each element is greater than the previous element.
For example, given the list [1, 3, 5, 4, 7, 9, 10, 8], the longest increasing sub... | codefeedback |
Design a system for managing a database of books. The system should include the following classes:
1. Book: Represents a book with attributes such as title, author, genre, publication year, and a unique ISBN number.
2. Library: Manages a collection of books. It should have methods to add a book, remove a book, search f... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.