instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Compute the square root of a number without using the square root function. The number can be a positive integer or a decimal number with up to 6 decimal places. The solution should have a time complexity of O(log n), where n is the given number. The solution should also be accurate up to 8 decimal places. Additionally... | codefeedback |
Explain in detail what the Global Interpreter Lock (GIL) is in Python, including its purpose, how it affects multi-threading in Python, and the potential drawbacks and advantages of having a GIL. Provide examples and discuss the trade-offs involved in using the GIL for multi-threading in Python. | codefeedback |
Find the greatest common divisor (GCD) of two positive integers, A and B, where A > B. You are not allowed to use the modulo operator. The time complexity of your solution should be O(log min(A, B)). | codefeedback |
Write a regular expression to match words containing exactly two 'a' characters, with at least one digit character before, between, and after the 'a' characters. | codefeedback |
Compare two objects and return 0 if they are equal, -1 if the first is less than the second, and 1 if the first is greater than the second. The objects can be integers or strings. Additionally, the comparison should be case-insensitive when comparing strings.
However, the comparison should be done by considering the A... | codefeedback |
Construct a for loop to print the prime numbers from 0 to 100. | codefeedback |
Make a list of the first 100 prime numbers that are also palindromic. | codefeedback |
Given a list of integers and strings, replace all the instances of the string 'x' with the string 'y' in the list, while maintaining the order of the elements. The list may contain duplicate elements.
Example:
Input:
[1, 2, 'x', 'x', 1, 'x', 'y', 'x']
Output:
[1, 2, 'y', 'y', 1, 'y', 'y', 'y']
Constraints:
- The le... | codefeedback |
Generate a random hex color in Python that starts with the letter 'F', has exactly 6 characters, and has at least two consecutive characters that are the same. | codefeedback |
Write a function that takes in a list of dictionaries as input and returns a list of keys in descending order based on the length of their corresponding values. Each dictionary in the input list represents a record of a person, where the keys are the attributes (e.g. 'Name', 'Age', 'City') and the values are the corres... | codefeedback |
Create a function in Ruby that takes in an integer as input and returns true if the number is a prime number and false otherwise. The function should include an if statement and should also check if the input number is less than or equal to 1. Additionally, the function should utilize the Miller-Rabin primality test al... | codefeedback |
Given an array of integers in Java, output all distinct items from the array in descending order. If there are duplicate items in the array, consider them as a single item and only include one occurrence of each item in the output. Additionally, calculate and output the sum of all distinct items in the array. | codefeedback |
Generate a C++ program to sum up the elements of an array, but with the following additional requirements:
1. The program should use a recursive function to calculate the sum.
2. The program should also calculate the product of the elements in the array using a separate recursive function.
3. The program should allow t... | codefeedback |
Create an HTML page with a layout consisting of 4 containers: one on the left, two in the middle, and one on the right. Each container should have a different background color.
Additionally, the left container should have a fixed width of 200px, the two middle containers should have equal width and be horizontally ali... | codefeedback |
Create a function in JavaScript that takes a number N as input and returns an array containing the Fibonacci series up to N. The Fibonacci series is a sequence of numbers in which each number is the sum of the two preceding ones, usually starting with 0 and 1.
In addition to returning the Fibonacci series, modify the... | codefeedback |
Increase the difficulty of the given programming test by imposing the following constraints:
1. Do not use any built-in Python functions or methods that directly reverse an array or list.
2. The time complexity should be O(n), where n is the length of the array.
3. The space complexity should be O(1), meaning no addit... | codefeedback |
Write a function in Python to split a given string into the words in the string.
The function should also handle the following special cases:
1. Handling multiple spaces, tabs, or newlines between words.
2. Ignoring leading and trailing spaces, tabs, or newlines in the input string.
3. Ignoring punctuation marks suc... | codefeedback |
Create a JavaScript class named "Student" that has the following fields and methods:
Fields:
1. name: A string representing the name of the student. (required)
2. age: A number representing the age of the student. (required)
3. grade: A number representing the grade of the student. (required)
Methods:
1. getGreeting(... | codefeedback |
Use regular expression to determine the number of words in a string, where a word is defined as a sequence of alphabetic characters separated by at least one space, punctuation mark, or digit. The string may contain special characters and must be case sensitive. This is a sample string with 10,000 words. | codefeedback |
Determine the time complexity and space complexity for the following code sample. Implement a solution that achieves a time complexity of O(n) and a space complexity of O(1). The input array will contain integers ranging from -1000 to 1000, and the array length will be between 1 and 1000. The solution should handle dup... | codefeedback |
Calculate the sum of all prime numbers between 3 and 17, inclusive, using JavaScript. Additionally, write a function that takes two parameters: the lower and upper limits, and returns the sum of all prime numbers within that range. | codefeedback |
Create a responsive HTML page with a dynamic title that displays the current date and time in the format "Day, Month DD, YYYY - HH:MM:SS". The page should include a header that contains a logo image. The logo image should be aligned to the right side of the header and should have a maximum width of 200 pixels. Addition... | codefeedback |
Design a data structure to model the evolution of a population, taking into account factors such as genetic mutations, environmental changes, competition for resources, and the impact of natural selection. The data structure should be able to track individual organisms, their traits, and their interactions within the p... | codefeedback |
Write a SQL query to select all the customers who have made at least 10 transactions in the past month, have an account balance of more than $1000, and have an average transaction amount greater than $500. | codefeedback |
Create a C++ variable with the name "name" that can store a string value, but the string must be exactly 10 characters long and contain only lowercase letters. Additionally, the string must have at least one vowel (a, e, i, o, or u) and one consonant (any letter that is not a vowel). | codefeedback |
Given a list of numbers, implement a quick sort algorithm that can handle a large input size of n (where n > 10^6) efficiently. The algorithm should have a time complexity of O(nlogn) and should not exceed the space complexity of O(logn). The input list may contain duplicate numbers and the algorithm should be able to ... | codefeedback |
Generate a unique 20 digit alphanumeric ID using Java, where the alphanumeric characters can only be uppercase letters (A-Z) and the numbers (0-9). The ID should have at least 8 distinct letters and at least 8 distinct numbers. The ID should also have at least one uppercase letter and one number at the beginning and at... | codefeedback |
Construct a for loop that calculates the sum of the numbers from 0 to n, but only include prime numbers in the sum. | codefeedback |
Generate a numpy array of shape (4,4) with random integer values between -100 and 100, where all the values in each row are unique, strictly increasing, and divisible by 3. | codefeedback |
Generate a class in Java for a contact record, including name, age, phone number, email, address, and additional social media information such as Facebook profile URL, Twitter handle, and Instagram username.
The class should also include methods to:
1. Validate the email address format.
2. Validate the phone number fo... | codefeedback |
Write a function to output the maximum value possible from a given array, with the constraint that the maximum value must be a prime number and also have a specific pattern. The specific pattern is defined as follows: the sum of the digits of the prime number must be divisible by 3.
Example:
Input: [10, 12, 15, 20, 22... | codefeedback |
Create a text classifier using supervised learning with a minimum accuracy requirement of 90% on the validation set. Additionally, the classifier should handle imbalanced datasets, where the ratio of positive to negative samples is at least 1:10. | codefeedback |
Using the Pandas library, parse the given json object and store the data in a dataframe. The dataframe should have the following columns: 'Name', 'Age', 'Street', 'City', 'State'. Additionally, add a new column called 'Country' which should contain the country name of each individual. | codefeedback |
Write a MySQL statement to sort the table results by the column "id" in ascending order, and then by the column "name" in descending order. Additionally, only include the rows where the column "status" is equal to 'active' and the column "age" is greater than 25. | codefeedback |
Find the product of the first N prime numbers, where N is a given positive integer. | codefeedback |
Write a Python program that efficiently reads a list of words and prints the most frequently used one. If there are multiple words that have the same highest frequency, print all of them. The program should not be case-sensitive when counting the frequency of words and should ignore any punctuation marks or special cha... | codefeedback |
Create a machine learning model that predicts whether an email is spam or not, while also identifying the specific type of spam, such as phishing, malware, fraudulent emails, or spoofing emails. The model should achieve an accuracy of at least 95% on a test dataset consisting of 10,000 emails. The model should also be ... | codefeedback |
Write a Python program to check whether a number is a Narcissistic number or not. A Narcissistic number is a number that is equal to the sum of its own digits raised to the power of the number of digits, where the power is a prime number. For example, 153 is a Narcissistic number because 1^3 + 5^3 + 3^3 = 1 + 125 + 27 ... | codefeedback |
Write a SQL query to return the 5 oldest employees from a table named 'employees', who have at least 10 years of work experience, are currently employed in the company, and have never been promoted during their tenure. | codefeedback |
Implement a function in JavaScript that returns true if an object is empty or contains only empty objects or arrays, false otherwise. Additionally, the function should handle nested objects and arrays. | codefeedback |
Create an array of 15 increasing numbers starting from 5, where each number is the sum of the previous three numbers in the array. | codefeedback |
Create a function 'greet' that takes a string parameter 'name' and returns the string 'Hello name!', where 'name' should be a non-empty string containing only alphabetic characters and have a maximum length of 10 characters. Additionally, the function should only return the greeting if the string 'name' is in all upper... | codefeedback |
Create a HTML form to take user input from a web page. Add client-side validation to ensure that the user enters a valid email address before submitting the form. Additionally, the form should include a password field with client-side validation to ensure that the password is at least 8 characters long and contains at ... | codefeedback |
Write a shell command to print the system IP address, but restrict the use of any built-in commands or utilities specific to a certain operating system or shell. Additionally, the command should only display the IP address if it is connected to the internet, and it should not rely on external APIs or websites to determ... | codefeedback |
Write a SQL query to select the users from table 'users' who are born after 1985, have at least 1000 followers, and whose total followers count is in the top 10% of all users. | codefeedback |
Explain the concept of polymorphism in programming and provide an example of how it can be implemented in a specific programming language of your choice. Additionally, demonstrate how polymorphism can be used in a real-world scenario, such as in a banking application where different types of accounts inherit from a com... | codefeedback |
Write a JavaScript function that extracts the domain name from an email address. The function should handle all possible scenarios, including email addresses with different top-level domains (e.g. .com, .org, .net) and email addresses with multiple subdomains. The function should also account for any special characters... | codefeedback |
Create an HTML form that takes three input fields - an email address, a password, and a confirm password. Add client-side validation to ensure that the email address field is not empty and follows the correct email format (e.g., example@example.com). Additionally, add client-side validation to the password field to ens... | codefeedback |
Categorize a given tweet based on sentiment, considering positive, negative, or neutral tones. Additionally, identify the sentiment strength as strong or weak. Your program should also handle multiple languages and be able to accurately categorize tweets with sarcasm or irony.
"This new software program is supposed to... | codefeedback |
Create a function in Java that takes a string as a parameter and returns the string in lowercase letters. However, you are not allowed to use any built-in string manipulation methods or libraries to convert the string to lowercase. Additionally, you must ensure that the function has a time complexity of O(n), where n i... | codefeedback |
Identify and fix the type of bug in the provided code snippet. The fixed code should handle a maximum of 100 characters in the message and return an error if the message exceeds this limit. Additionally, the function should only allow alphabetic characters in the message and ignore any non-alphabetic characters. | codefeedback |
Create a function 'subStr' that takes a string and a start and end index and returns a substring between the start and end index. The start index should be inclusive, but the end index should be exclusive. The function should have a time complexity of O(n), where n is the length of the string.
In addition to the orig... | codefeedback |
Write a method 'addString' in Java that takes two strings as parameters and returns a single string that concatenates the two strings. The method should also remove any duplicate characters in the resulting string, and the characters should be sorted in ascending order. Additionally, the method should ensure that all u... | codefeedback |
Design a program to select the names of the students who have secured more than 80% marks in a given exam. The program should also calculate and display the average marks of all the students.
students = [("John", 75), ("Mary", 90), ("Simon", 80), ("Rose", 80)]
In addition to finding the students who have secured more... | codefeedback |
Design a class in C++ to represent a 2D point with integer coordinates and define the following operations for two points:
1. Addition: Add two points and return a new point with the sum of their coordinates.
2. Subtraction: Subtract one point from another and return a new point with the difference of their coordinates... | codefeedback |
Construct a SQL query to get the names, address, age, and salary of employees who have been with the company for more than 5 years, are in the sales department, and have a salary higher than the average salary of all employees in the company. Additionally, include the number of years of experience each employee has, ca... | codefeedback |
New Constraints and Requirements:
1. The code must use only the "iostream" header for input/output operations.
2. The code must not use any additional libraries or headers.
3. The code must not use any predefined C++ functions or classes.
4. The code must be written using only pointer arithmetic and bitwise operations.... | codefeedback |
Suggest an additional function needed to complete the following program. The function should reverse a linked list in-place.
class Node:
def __init__(self, data):
self.data = data
self.next = None
def reverse_list(self):
# Implementation of the reverse_list function
# Your code... | codefeedback |
Modify the given code to accept input in Celsius and convert it to Fahrenheit. Make sure to handle any potential errors. Additionally, the program should display a warning message if the temperature is below freezing (0 degrees Celsius) and an error message if the temperature exceeds 100 degrees Celsius. | codefeedback |
Write a pseudocode to compare two strings and determine which string has more unique characters. Additionally, implement a function that returns the count of each unique character in each string. | codefeedback |
Extract the unique elements from a given list of numbers while maintaining the original order of occurrence and count the frequency of each unique element.
list_of_nums = [5, 2, 5, 3, 7, 8, 2]
Time Complexity Requirement: O(n)
Space Complexity Requirement: O(n)
You are not allowed to use any built-in functions or li... | codefeedback |
Define a function to compare two strings using only bitwise operations. The function should have a time complexity of O(n), where n is the length of the longer string. Additionally, the function should use a constant amount of additional space. | codefeedback |
Provide instructions to create a doubly linked list in Java with the following constraints: each node should store both a key and a value, the list should support adding nodes at the head and tail, and the list should have a method to remove a node given its key. Additionally, ensure that the remove method handles the ... | codefeedback |
Implement a function in Python to find the square root of a given number using the Newton-Raphson method, without using the built-in square root function or any math libraries.
Number: 256
The function should return the square root of the given number accurate up to 5 decimal places. | codefeedback |
Explain the purpose of the try-except block and provide a code example that demonstrates the use of nested try-except blocks to handle different types of exceptions. Additionally, modify the code example to include a requirement where the program must log each exception to a separate log file, with a maximum of 100 log... | codefeedback |
Modify the given code snippet to make all elements of the list uppercase and remove any duplicates. Additionally, use a for loop to iterate through the list and print each element twice. The code should be implemented in a recursive function and the final list should be sorted in descending order. | codefeedback |
Write a function that takes in a positive integer from the user and returns the sum of all the odd numbers from 1 to that number multiplied by 3. The function should handle inputs greater than 1. Additionally, you should handle the case where the input is a negative number, and return an error message stating that only... | codefeedback |
Design a data structure in Python to store customer contact details, ensuring that each customer can have multiple contact numbers and email addresses associated with them. Additionally, implement a method to retrieve all customers who have a specific email domain (e.g., "gmail.com").
# Reference Erroneous Code #
"""
... | codefeedback |
Implement a function to generate the Fibonacci series upto 'n' terms, where n is a positive integer less than or equal to 50. The function should handle input validation and throw an error if n is not within the specified range. Additionally, the function should check if the input number is prime and if so, it should r... | codefeedback |
Parse the given markup language to extract out the attributes and their corresponding values, and then calculate the sum of all the numeric values found in the attributes.
Constraints:
- The markup language contains nested elements.
- The attributes can be present at any level of nesting.
- The attribute values can be... | codefeedback |
Explain the purpose of a deadlock in a multithreaded program and describe a situation where a deadlock may occur with at least five threads, each requiring a specific resource, and provide a solution to prevent deadlock. Additionally, consider the scenario where the resources have varying levels of availability and pri... | codefeedback |
Write a Regular Expression to identify all words that end with "ing" and contain at least two consecutive vowels. | codefeedback |
Given a sentence, identify the parts of speech and their corresponding functions in the sentence.
Sentence: "John said: "Let's go to the zoo."
Steps to follow:
1. Tokenize the sentence into individual words.
2. Use a part-of-speech tagging tool or library to assign a part of speech tag to each word.
3. Identify the ... | codefeedback |
Given a byte sequence, identify the sequence that produces the following output: "𝕳 𝖊 𝖑 𝖑 𝖔 𝖂 𝖔 𝖗 𝖑 𝖉 !" where each character is represented by a Unicode code point.
#Additional Instructions#
1. The byte sequence should consist of UTF-8 encoded characters only.
2. The byte sequence should be in the range o... | codefeedback |
Explain what a deadlock is in operating systems and elaborate on the necessary conditions for a deadlock to occur. Additionally, provide a real-world example of a deadlock situation and describe the steps that can be taken to prevent or resolve it. | codefeedback |
Remove the duplicate elements from a list, while maintaining the order of the elements. The list can contain both positive and negative integers. Additionally, the solution should have a time complexity of O(n) and should not use any built-in functions or libraries for removing duplicates. list1 = [-2, 4, 6, 8, 10, -2,... | codefeedback |
Read the code and determine all the variables that have been declared or used.
Rewritten Test:
def func(x, y, z):
a = x + y + z
b = x * y * z
c = a / b
d = a % b
e = b ** 2
f = a // b
g = c * d * e * f
h = (x + y) / z
i = a + b + c + d + e + f + g + h
return i
In this... | codefeedback |
Suggest an optimized solution to the following problem: Write a program that sorts a list of strings in alphabetical order using a divide-and-conquer approach. The program should handle a large number of strings (up to 10^6) efficiently. Implement your solution in Python. The input list of strings, list_of_strings, may... | codefeedback |
We need to find all unique combinations of at least 2 elements from a given list of items, such that the sum of the combination is equal to a given target value. Additionally, each combination should not contain any duplicate elements.
List: [1, 2, 3, 4]
Target value: 10 | codefeedback |
Create a function to test if a given integer is a prime palindrome number. A prime palindrome number is a number that is both prime and a palindrome.
A palindrome number is a number that remains the same when its digits are reversed. For example, 121 and 333 are palindrome numbers.
To solve this problem, you need to ... | codefeedback |
Implement a function that performs matrix addition for two given matrices. The matrices are represented as two-dimensional arrays, where each array represents a row of the matrix. The function should return the result matrix.
The matrices can have varying sizes, but are guaranteed to have the same number of rows and c... | codefeedback |
Create a Regular Expression to match URLs, but also capture and extract specific parts of the URL such as the domain name, query parameters, and subdomains. Additionally, handle edge cases such as URLs with special characters or non-standard port numbers. | codefeedback |
Implement an in-place Merge Sort algorithm in C++, where the input array cannot be modified and the sorting must be done without using any additional data structures. Additionally, the merge step must be implemented using a non-recursive approach. | codefeedback |
Create a set of transformation rules to convert a valid XML document to a valid HTML document, while preserving the nested structure and attributes of the elements. Additionally, ensure that any references to external resources, such as images or stylesheets, are properly translated to the corresponding HTML tags. The ... | codefeedback |
We need to build a function to compute the product of the elements of a given array, but with the following constraints:
1. The function should only consider the elements that are multiples of 3 and 5 in the array.
2. The function should ignore any element that is equal to 2 or 3 in the array.
3. The function should ha... | codefeedback |
Develop a convolutional neural network (CNN) for image classification using a deep learning framework. The CNN should have at least 8 convolutional layers and 4 fully connected layers. Each convolutional layer should have a different number of filters and kernel sizes. Implement a suitable activation function for each ... | codefeedback |
We need to write a program to generate all permutations of a given string, but with the following additional constraints:
1. The program should not use any built-in libraries or functions for generating permutations.
2. The program should be able to handle strings of length up to 15 characters.
3. The program should ou... | codefeedback |
Create a function that takes a string and a number n, then return the n characters from the end of the string in reverse order. Additionally, ensure that the function can handle string inputs containing special characters such as punctuation marks, whitespace, and non-alphanumeric characters. The function should also h... | codefeedback |
Calculate the sum of all lowercase vowels in a string using a for loop, but exclude any characters that are not letters.
String: Pyth1n | codefeedback |
Compute the probability of rain given that the grass is wet, given that the probability of the grass being wet when it rains is 0.8, the overall probability of rain is 0.4, the overall probability of the grass being wet is 0.7, and you can only use a constant amount of additional memory (i.e., no data structures can be... | codefeedback |
Create a function that takes two strings, two string lengths, and returns true if the second string is a rotation of the first. A rotation is defined as shifting all the characters of a string by a certain number of positions and wrapping around to the beginning.
Example:
```python
string1 = "Hello World"
string2 = "... | codefeedback |
Create a SQL query to find all employees whose salary is greater than the average salary of their department, whose years of experience is greater than 5, and whose position is either "manager" or "senior manager". Ensure that the query does not include any employees whose name starts with the letter "A". Additionally,... | codefeedback |
You are given a list of numbers and you need to calculate the standard deviation of the numbers. The input list can contain duplicate numbers.
Write a function `calculate_standard_deviation(nums: List[int]) -> float` that takes in a list of integers `nums` and returns the standard deviation as a float.
The standard d... | codefeedback |
Solve the quadratic equation 3x^2 + 8x + 4 = 0 using the quadratic formula, while also calculating and displaying the discriminant value and the nature of the roots. Additionally, implement a function that takes in the coefficients of a quadratic equation as input and returns the solutions, discriminant value, and natu... | codefeedback |
Please create a program that takes a string of words and returns the count of each word, while excluding common English stop words. The program should be able to handle very large input strings efficiently.
word_string = "This is a sentence of words"
Additional requirements:
1. The program should ignore case sensitiv... | codefeedback |
Implement an efficient algorithm to generate all the distinct permutations of a string of length n, but you are not allowed to use any built-in functions or libraries to generate permutations. Your algorithm should have a time complexity of O(n!). You must implement the algorithm from scratch using only basic programmi... | codefeedback |
Write a program that sorts a list of positive integers in ascending order based on the sum of their prime factors, and if the sums are equal, sort them based on the number of distinct prime factors of each element. The program should handle lists with up to 10^6 elements efficiently. | codefeedback |
Construct a binary search tree from a list of given items, ensuring that the tree is balanced.
Items: [1, 5, 7, 9, 11, 16, 19, 23, 27, 29, 31, 35, 37, 41, 43, 47, 53, 59, 61, 67]
Erroneous code reference:
int binarySearchTree(List<int> items) {
if (items.isEmpty) {
return null;
}
int mid = it... | codefeedback |
Write a Python parser to parse the json string to a dictionary, ensuring that all keys in the dictionary are unique and that all values are of type string. The parser should also be able to handle nested json objects and arrays within the string.
Additionally, the parser should be able to handle different data types o... | codefeedback |
Write a function in Python that takes a list of integers as an argument and calculates the mean average. Additionally, ensure that the function handles cases where the list is empty and returns a meaningful error message in such cases. The function should also handle cases where the list contains non-integer elements a... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.